I am to use the Math Library to do some calculations on an array.
I tried something like this:
import numpy as np
import math
a = np.array([0, 1, 2, 3])
a1 = np.vectorize(a)
print("sin(a) = \n", math.sin(a1))
Unfortunately it does not work. An error occur: "TypeError: must be real number, not vectorize".
How can I use the vectorize function to be able to calculate that kind of things?
vectorizeexpects you to pass a function, but you passed an array. Andmath.sinof course expects you to pass a number, but you've passed avectorized(essentially a function). What are you actually trying to accomplish?np.sin(a)(no need to import math; no need to mix these, and especially no need to use vectorize).np.sinis to be avoided is to definef=np.vectorize(math.sin)and applyf(a).