From 'array' or 'matrix'? What should i use? in the Numpy section for Matlab wiki users :
For an array, 1xN, Nx1, and N vector shapes are two different things. Operations of type A [:, 1] return an array of rank 1 of form N, and not rank-2 of form Nx1. Transposing in a rank-1 array does nothing.
Here is an example showing that they do not match:
>>> import numpy as np >>> a1 = np.array([1,2,3]) >>> a1 array([1, 2, 3]) >>> a2 = np.array([[1,2,3]])
So, are you sure that all your arrays are 2d arrays or some of them are 1d arrays?
If you want to use the array[0,:] command, I would recommend using 1xN 2d arrays instead of 1d arrays. Here is an example:
>>> a2 = np.array([[1,2,3]])
Matthew rankin
source share