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?
The whole point of numpy is that you don't need any
math
method or any list comprehension:You can use
a
as if it were a scalar and you get the corresponding array.If you really need to use
math.sin
(hint: you don't), you can vectorize it (the function itself, not the array):math.sin requires one real number at a time.