Issue
How do I create a 0 x 0 (i.e. ndim
= 2, shape
= (0,0)) numpy.ndarray
of float
?
Solution
>>> import numpy as np
>>> a = np.empty( shape=(0, 0) )
>>> a
array([], shape=(0, 0), dtype=float64)
>>> a.shape
(0, 0)
>>> a.size
0
The array above is initialized as a 2D array--i.e., two size parameters passed for shape.
Second, the call to empty is not strictly necessary--i.e., an array having 0 size could (i believe) be initialized using other array-creation methods in NumPy, e.g., NP.zeros, Np.ones, etc.
I just chose empty because it gives the smallest array (memory-wise).
Answered By - doug
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.