git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]# Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Markos, I can explain the difference from a non-numpy point of view - I hope you will be able to see how this difference affects what you are trying to do in numpy. vector_1 is an np.array consisting of a three-element list, with the three elements being 1, 0 and 1. vector_2 is an np.array consisting (at the top level) of a one-element list, with that element (at this top level) being a three-element list, with these three elements (at the lower level) being 1, 0 and 1. Stephen. On Fri, Jun 21, 2019 at 7:29 AM Markos <markos at c2o.pro.br> 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 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 > -- > https://mail.python.org/mailman/listinfo/python-list >

- Prev by Date:
**Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )** - Next by Date:
**Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )** - Previous by thread:
**Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )** - Next by thread:
**Difference between array( [1,0,1] ) and array( [ [1,0,1] ] )** - Index(es):