[SciPy-user] shape

Gael Varoquaux gael.varoquaux@normalesup....
Thu Apr 26 14:47:21 CDT 2007


On Thu, Apr 26, 2007 at 11:38:11AM -0700, linda.s wrote:
> I am curious about the (9,) for the shape. Does it mean 9 rows one
> column or one row 9 columns? The final array looks like one row 9
> columns but why (9,) gives me an impression that it is 9 rows one
> column? Thanks.

Rows and columns have a meaning only for 2D arrays.

shape=(9,1) is a 9 rows vector:

a = array([[2], [4], [6], [8], [10], [12], [14], [16], [18]])

shape=(1,9) is a 9 columns vector:

a = array([[2, 4, 6, 8, 10, 12, 14, 16, 18]])

You can suppress the dimensions of length 1 with the numpy function
"squeeze".

HTH,

Gaël


More information about the SciPy-user mailing list