Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )

Markos markos at c2o.pro.br
Thu Jun 20 21:39:14 EDT 2019


Hi,

I'm studying Numpy and I don't understand the difference between

>>> vector_1 = np.array( [ 1,0,1 ] )

with 1 bracket and

>>> vector_2 = np.array( [ [ 1,0,1 ] ] )

with 2 brackets

The shape of vector_1 is:

>>> vector_1.shape
(3,)

But the shape of vector_2 is:

>>> vector_2.shape
(1, 3)

The transpose on vector_1 don't work:

>>> vector_1.T
array([1, 0, 1])

But the transpose method in vector_2 works fine:

>>> vector_2.T
array([[1],
        [0],
        [1]])


I thought that both vectors would be treated as an matrix of 1 row and 3 
columns.

Why this difference?

Any tip?

Thank you,
Markos



More information about the Python-list mailing list