[Tutor] difference between array([1,0,1]) and array([[1,0,1]])
Mats Wichmann
mats at wichmann.us
Fri Jun 21 09:36:19 EDT 2019
On 6/20/19 5:39 PM, Markos wrote:
> 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 first is one-dimensional, the second two-dimensional. If we expand
how we write the second a bit does it make it more clear?
np.array([
[1, 0, 1],
# no other elements
])
the double brackets look magical, but as soon as you have more than one
row it makes sense.
>
> 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
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list