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 = [[[-9.035250067710876], [7.453250169754028], [33.34074878692627]], [[-6.63700008392334], [5.132999956607819], [31.66075038909912]], [[-5.1272499561309814], [8.251499891281128], [30.925999641418457]]] N = 200 test(X, N)
I am getting error as
AttributeError: 'list' object has no attribute 'shape'
So, I think I need to convert my X to numpy array?
The Python "AttributeError: 'list' object has no attribute 'shape'" occurs when we try to access the shape attribute on a list. To solve the error, pass the list to the numpy. array() method to create a numpy array before accessing the shape attribute.
Use numpy. array to use shape attribute.
The shape of a list will be obtained using a built-in function len() and a module NumPy. The shape of a list normally returns the number of objects in a list. We can calculate a shape of a list using two methods, len() and NumPy array shape. Numpy has an attribute named np.
Use numpy.array
to use shape
attribute.
>>> import numpy as np >>> X = np.array([ ... [[-9.035250067710876], [7.453250169754028], [33.34074878692627]], ... [[-6.63700008392334], [5.132999956607819], [31.66075038909912]], ... [[-5.1272499561309814], [8.251499891281128], [30.925999641418457]] ... ]) >>> X.shape (3L, 3L, 1L)
NOTE X.shape
returns 3-items tuple for the given array; [n, T] = X.shape
raises ValueError
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With