Below is my short code, but it has an error: "AttributeError: 'numpy.ndarray' object has no attribute 'sin'"
. I don't understand why and how to fix. Please guide me!
Thanks a lot in advance!
import numpy as np
w1 = 0.3
w2 = 0.2
w0 = 0.4
x1 = np.linspace(0, 10, 50)
x2 = np.linspace(0, 10, 50)
X, Y = np.meshgrid(x1, x2)
A = np.array([1,X,Y],dtype=object)
w = np.array([[w0],[w1],[w2]])
Z = np.sin(A.dot(w))
print (Z)
Because you define A
with dtype=object
, the result of A.dot(w)
will be of type object as well. As a consequence of this, numpy.sin
tries to call sin
as a member function of the elements in the result of A.dot(w)
which is not defined.
Produces error: np.sin(np.array([np.array(1)], dtype=object))
No error: np.sin(np.array([np.array(1)]))
As @Adelin has mentioned above, simply call np.sin(A.dot(w)[0]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.