'list' object has no attribute 'shape'

后端 未结 7 780
执笔经年
执笔经年 2020-12-07 22:13

how to create an array to numpy array?

def test(X, N):
    [n,T] = X.shape
    print \"n : \", n
    print \"T : \", T



if __name__==\"__main__\":

    X =         


        
7条回答
  •  不知归路
    2020-12-07 22:51

    list object in python does not have 'shape' attribute because 'shape' implies that all the columns (or rows) have equal length along certain dimension.

    Let's say list variable a has following properties: a = [[2, 3, 4] [0, 1] [87, 8, 1]]

    it is impossible to define 'shape' for variable 'a'. That is why 'shape' might be determined only with 'arrays' e.g.

    b = numpy.array([[2, 3, 4]
                    [0, 1, 22]
                    [87, 8, 1]])
    

    I hope this explanation clarifies well this question.

提交回复
热议问题