2019年1月8日 星期二

[python] 快速批次處理陣列資料

    test_a = np.asarray([1, 5, 6])
    test_b = np.asarray([0.1, 0.2, 0.3])

    print('filter out = ', (test_b <= 0.2) * test_b)  # [0.1, 0.2, 0]
    test_a[test_b <= 0.2] = 10   # [10, 10, 6]
    test_a[[True, False, True]] = 123 # [123, 10, 123]
    test_a[np.asarray([1, 2])] = 456  # [123, 456, 456]