What does .shape[] do in “for i in range(Y.shape[0])”?

前端 未结 6 744
攒了一身酷
攒了一身酷 2020-12-22 18:01

I\'m trying to break down a program line by line. Y is a matrix of data but I can\'t find any concrete data on what .shape[0] does exactly.

6条回答
  •  情话喂你
    2020-12-22 18:51

    shape is a tuple that gives dimensions of the array..

    >>> c = arange(20).reshape(5,4)
    >>> c
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11],
           [12, 13, 14, 15],
           [16, 17, 18, 19]])
    
    c.shape[0] 
    5
    

    Gives the number of rows

    c.shape[1] 
    4
    

    Gives number of columns

提交回复
热议问题