[Numpy-discussion] min depth to nonzero in 3d array

Alan G Isaac alan.isaac at gmail.com
Thu Apr 17 12:32:42 EDT 2014

Given an array A of shape m x n x n
(i.e., a stack of square matrices),
I want an n x n array that gives the
minimum "depth" to a nonzero element.
E.g., the 0,0 element of the result is
Can this be vectorized?
(Assuming a nonzero element exists is ok,
but dealing nicely with its absence is even better.)

Alan Isaac

More information about the NumPy-Discussion mailing list