How to extract a zero dimensional slice from a one dimensional array in numpy
Is there a way to slice a zero dimensional submatrix from a one dimensional array?
For example, if I have N-dimensional
returns (N-1) -dimensional
However, if I have a 1-dimensional
does not return a 0-dimensional ndarray, but rather a
def increment(zero_d_array): zero_d_array[...] = zero_d_array + 1 counter = numpy.array(0) # a zero-dimensional array containing scalar 0 increment(counter) # success; counter is now 1 counters = numpy.zeros(3, dtype=int) # [0, 0, 0] increment(counter) # fails; counter is a numpy.int64, not a 0-D array
I understand that the above will work with
, but only because it
works with both 0-D and 1-D inputs. Not all features will be that flexible.
source to share