相当于 np.array 拆分为屏蔽数组

Equivalent of np.array split for masked array

numpy.ma.split_array 不存在。

因此,如果 arr 是掩码数组,以下代码是否按预期工作?

np.array_split(arr, multiprocessing.cpu_count())

如果不是,我应该如何定义一个函数split_masked_array来实现类似的行为?

不确定您为什么不尝试。似乎有效,但很难确定,因为您没有提供 minimal reproducible example,所以我不知道“按预期工作”是什么意思。

In [5]: x = np.ma.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], mask=[[1, 0, 0], [0, 1, 0], [0, 0, 1]])

In [6]: x
Out[6]:
masked_array(
  data=[[--, 2, 3],
        [4, --, 6],
        [7, 8, --]],
  mask=[[ True, False, False],
        [False,  True, False],
        [False, False,  True]],
  fill_value=999999)

In [7]: np.array_split(x, 3)
Out[7]:
[masked_array(data=[[--, 2, 3]],
              mask=[[ True, False, False]],
        fill_value=999999),
 masked_array(data=[[4, --, 6]],
              mask=[[False,  True, False]],
        fill_value=999999),
 masked_array(data=[[7, 8, --]],
              mask=[[False, False,  True]],
        fill_value=999999)]