I'm new to numpy and have been tasked with the following situation: I need to create two numpy arrays of random integers (between 0 + 1). One numpy array represents the x-coordinates and the other one represents the y-coordinates. I then need to check to see if the points fall inside a circle of radius one by using squareroot(x^2 + y^2) < 1.
I'm currently just trying to square my arrays and add them together. What is probably a very simple task is giving me no ends of trouble.
import matplotlib.pyplot as plt
import numpy as np
plots = 100
dataOne = np.random.random(size = plots)
dataTwo = np.random.random(size = plots)
circle = plt.Circle((0,0), 1, alpha = 0.1)
plt.gca().add_patch(circle)
plt.xlim(0, 5)
plt.ylim(0, 5)
plt.show()
squareDataOne = dataOne ** 2
squareDataTwo = dataTwo ** 2
if squareDataOne + squareDataTwo < 1:
print("Now check square-root!")
I keep receiving an error message: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(). Could anyone explain why Python/Numpy does not like this? I've been told to try and use a Boolean expression to slice the array. Can anyone provide suggestions on the best way to incorporate this into my given code? Any suggestions or tips for a newbie are appreciated.