0

I have two numpy arrays (plot_x and plot_y) of the same length where plot_y is calculated based off on the values of plot_x. I want to filter the first array plot_x such that 0.1<=plot_x<=10 and filter the second array plot_y such that it contains the values that corresponds to the values in plot_x so that I can plot them in a graph. How do I do that? Thank you in advance.

2
  • Can you please share a sample of your code? It might helps Commented Apr 21, 2021 at 13:32
  • first filter plot_x and later calculate plot_y using already filtered plot_x. OR you would have to keep it as pairs (x from plot_x, y from plot_y) to filter it aftre calculations. Commented Apr 21, 2021 at 13:54

1 Answer 1

1

Filtering the data using Numpy-module is one of the basic operation, one of the simplest way is :

LOGIC :
1. Define Masking Matrix which we will use to filter the data.

condn = np.logical_and(X<5, X>0)

2. Using subscription operator [] we can access desired data with condition masking-matrix should follow Broadcasting-Properties.

X_u = X[condn]
Y_u = Y[condn]

CODE :

import numpy as np

X = np.array([-1, -3, 1,-5, 2, 3,-6, 4, 5,-9, 6, 7, 8])
Y = np.array([i**3 for i in X])

condn = np.logical_and(X<5, X>0)
# for shortcut you can use => condn = (X<5) & (X>0)

X_u = X[condn]
Y_u = Y[condn]
print(X_u)
print(Y_u)

OUTPUT :

[1 2 3 4]
[ 1  8 27 64]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.