Reputation: 11
I am trying to create an array of evenly spaced elements ranging from -n to n. (ex: -2, 2, up to 1000 evenly spaced elements). Then using the array to create 2 new arrays using 2 equations by doing vector arithmetic.
import numpy as np
from math import sqrt
width = 4
intervals = 1000
xCoords = np.linspace(-width/2, width/2, intervals+1)
yList1 = sqrt(1 - ((abs(xCoords) - 1)**2))
yList2 = -3 * sqrt(1 - sqrt((abs(xCoords)/2)))
print(yList1)
I am getting the following error:
TypeError: only size-1 arrays can be converted to Python scalars
Upvotes: 0
Views: 115
Reputation: 327
Use numpy functions on numpy arrays instead of the math
library functions. Try np.sqrt
and np.abs
Upvotes: 2