jvnna - 1 year ago 67

Python Question

I have 2 arrays of random numbers, one array (X) representing x-coordinates and one array (Y) representing y-coordinates. I want to filter the X array such that I only keep the indices (i) of X where X[i]^2 + Y[i]^2 < 1.

I know how to filter with values in 1 array but since I need to use 2, I am not sure what to do. I am not allowed to use loops of any kind.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

This will do:

```
X_filtered = X[X**2 + Y**2 < 1]
```

`X**2 + Y**2 < 1`

returns a boolean array and accessing `X`

on this array returns the `X`

only at the indices equal to `True`

.

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**