what does numpy ndarray shape do?

后端 未结 4 1906
野的像风
野的像风 2020-12-04 14:10

I have a simple question about the .shape function, which confused me a lot.

a = np.array([1, 2, 3])   # Create a rank 1 array
print(type(a))            # P         


        
4条回答
  •  情话喂你
    2020-12-04 14:51

    .shape() gives the actual shape of your array in terms of no of elements in it, No of rows/No of Columns. The answer you get is in the form of tuples.

    For Example: 1D ARRAY:

    d=np.array([1,2,3,4])
    print(d)
    (1,)
    

    Output: (4,) ie the number4 denotes the no of elements in the 1D Array.

    2D Array:

    e=np.array([[1,2,3],[4,5,6]])   
    print(e)
    (2,3)
    

    Output: (2,3) ie the number of rows and the number of columns.

    The number of elements in the final output will depend on the number of rows in the Array....it goes on increasing gradually.

提交回复
热议问题