I'm trying to understand how a np.array can be created with shape(0,2).
Is this even possible?
So
np.array([]).shape
#output (0,)
np.array([[],[]]).shape
#output (2, 0)
can I get (0, 2) ?
(without using .T)
Use a function such as np.zeros
. No need to worry about the value it generates since there are no values in a 0 x 2 array:
arr = np.zeros((0, 2))
arr.shape
(0, 2)
It can be done by np.empty((0,2))
or np.zeros((0,2))
.
np.empty()
, unlike np.zeros()
, does not set the array values to zero and it is slightly faster.
Extra information:
In your code np.array([]).shape
outputs a rank-1 array which is equal to its transpose.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With