Coo*_*rab 3 python arrays selection
我有两个数组,比方说x和y包含几千个数据点.绘制散点图可以很好地表示它们.现在我想选择一定范围内的所有点.例如r = 10
我试过这个,但它不起作用,因为它不是网格.
x = [1,2,4,5,7,8,....]
y = [-1,4,8,-1,11,17,....]
RAdeccircle = x**2+y**2
r = 10
regstars = np.where(RAdeccircle < r**2)
Run Code Online (Sandbox Code Playgroud)
这与nxn数组不同,并且RAdeccircle = x**2+y**2似乎不起作用,因为它不会尝试所有排列.
你只能**在一个numpy数组上执行,但在你的情况下你使用列表,并**在列表上使用返回一个错误,所以你首先需要使用列表转换为numpy数组np.array()
import numpy as np
x = np.array([1,2,4,5,7,8])
y = np.array([-1,4,8,-1,11,17])
RAdeccircle = x**2+y**2
print RAdeccircle
r = 10
regstars = np.where(RAdeccircle < r**2)
print regstars
>>> [ 2 20 80 26 170 353]
>>> (array([0, 1, 2, 3], dtype=int64),)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
649 次 |
| 最近记录: |