. Advertisement .
..3..
. Advertisement .
..4..
I get the error message:
AttributeError: 'list' object has no attribute 'shape'
Has anyone ever faced this problem? How to troubleshoot the “attributeerror: ‘list’ object has no attribute ‘shape’.” The problem appears when I try to operate the following program:
def test(X, N):
[n,T] = X.shape
print "n : ", n
print "T : ", T
if __name__=="__main__":
X = [[[-9.035250067710876], [7.453250169754028], [33.34074878692627]], [[-6.63700008392334], [5.132999956607819], [31.66075038909912]], [[-5.1272499561309814], [8.251499891281128], [30.925999641418457]]]
N = 200
test(X, N)
The cause: For the provided array,
X.shape
results a 3-item tuple, so[n, T] = X.shape
generates a ValueError: ‘list’ object has no attribute ‘shape’.Solution:
Shape
attribute should be used withnumpy.array
.Alternativ, you could use
np.shape(...)
Take, for example:
np.shape(a)
will output(3,)