我有两个 10x2x2 complex64 数组。我想找出哪些 2x2 数组中的一个或两个不是全为零:
import numpy
a = numpy.zeros((10,2,2), "complex64")
b = numpy.ones((10,2,2), "complex64")
empty_one_or_both = (a.reshape(10,4) != 0).all(axis=1) * (b.reshape(10,4) != 0).all(axis=1) # EDIT
目标是仅对非空对执行其他操作,例如:
numpy.sqrt(a[empty_one_or_both])
有没有更好的办法?