有没有办法获取包含 1-7 之间浮点数的数据集并为其设置范围,以便我只使用 2.6 到 5 之间的数字?
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
这给出了
的错误
---------------------------------------------------------------------------
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
numpy.clip(a, a_min, a_max, out=None, **kwargs
编辑 如果你想从数组中删除这些值而不是剪切它们,你只需要 re-make 你的数组:
>>> 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])
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
这给出了
的错误---------------------------------------------------------------------------
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
numpy.clip(a, a_min, a_max, out=None, **kwargs
编辑 如果你想从数组中删除这些值而不是剪切它们,你只需要 re-make 你的数组:
>>> 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])