In numpy, is it recommended to create column arrays (2d arrays) rather than 1d arrays? For example, whereas Z = np.zeros((12,)) defines a 1-dimensional list, it might also be preferable to form Z = np.zeros((12,1)).
-
1Use the 1-d array by default. Only use the 2-d shape when you know you need it.Warren Weckesser– Warren Weckesser2014-01-09 18:31:51 +00:00Commented Jan 9, 2014 at 18:31
Add a comment
|
1 Answer
Depends on the use case. Both possibilities exist for a reason: if Z can be a matrix but just happens to have one column, make it a column vector. If Z is always a single vector, make it 1-d unless some operation (or library) requires the other format; 1-d is usually a bit easier to work with.