Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to take a dataset that contains floats between 1-7 and set a range to it so that I only use numbers between 2.6 and 5?

import numpy as np
import matplotlib.pyplot as plt
data = np.loadtxt('Area_-116_32.txt', usecols = 2)
plt.hist(data, bins=40, range=[2.6,5], log=10)
e= np.array(data) 
condition = np.mod(e)>2.6 and np.mod(e)<5

this gives an error of

TypeError Traceback (most recent call last)
Input In [34], in <cell line: 1>()
—-> 1 condition = np.mod(e)>2.6 and np.mod(e)<5

TypeError: remainder() takes from 2 to 3 positional arguments but 1 were given

example of some of the data

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, numpy’s clip function

numpy.clip(a, a_min, a_max, out=None, **kwargs

Edit if you want to remove those values from the array instead of clipping them, you just need to re-make your array:

>>> x=np.array([3, 6, 7, -2, -5, -1, -1, 3, 1, -1, -2, -1, -5, -1])
>>> x[(x>-2) & (x<6)]
array([ 3, -1, -1,  3,  1, -1, -1, -1])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading