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

前端 未结 6 746
攒了一身酷
攒了一身酷 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:47

    In python, Suppose you have loaded up the data in some variable train:

    train = pandas.read_csv('file_name')
    >>> train
    train([[ 1.,  2.,  3.],
            [ 5.,  1.,  2.]],)
    

    I want to check what are the dimensions of the 'file_name'. I have stored the file in train

    >>>train.shape
    (2,3)
    >>>train.shape[0]              # will display number of rows
    2
    >>>train.shape[1]              # will display number of columns
    3
    

提交回复
热议问题