I need to make a multidimensional array of zeros.
For two (D=2) or three (D=3) dimensions, this is easy and I'd use:
a = numpy.zeros(shape=(n,n))
or
a = numpy.zeros(shape=(n,n,n))
How for I for higher D, make the array of length n?
>>> sh = (10, 10, 10, 10)
>>> z1 = zeros(10000).reshape(*sh)
>>> z1.shape
(10, 10, 10, 10)
While above is not wrong, it's just excessive.
np.zeros doesn't already support. How is this better than np.zeros(sh)?np.zeros(sh) works.In [4]: import numpy
In [5]: n = 2
In [6]: d = 4
In [7]: a = numpy.zeros(shape=[n]*d)
In [8]: a
Out[8]:
array([[[[ 0., 0.],
[ 0., 0.]],
[[ 0., 0.],
[ 0., 0.]]],
[[[ 0., 0.],
[ 0., 0.]],
[[ 0., 0.],
[ 0., 0.]]]])