Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python两个数组,获取半径内的所有点_Python_Arrays_Selection - Fatal编程技术网

Python两个数组,获取半径内的所有点

Python两个数组,获取半径内的所有点,python,arrays,selection,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) x=[1,2,4,5,7,8,…] y=[-1,4,8,-1,11,17,…]

我有两个数组,比如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)
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

这与nxn阵列不同,
RAdeccircle=x**2+y**2
似乎不起作用,因为它不会尝试所有排列

您只能在numpy数组上执行
**
,但在您的情况下,您使用的是列表,并且在列表上使用
**
会返回错误,因此您首先需要使用
np.array()将列表转换为numpy数组。

将numpy导入为np
x=np.数组([1,2,4,5,7,8])
y=np.数组([-1,4,8,-1,11,17])
RAdeccircle=x**2+y**2
打印RAdeccircle
r=10
regstars=np.where(RAdeccircle>> [  2  20  80  26 170 353]
>>>(数组([0,1,2,3],dtype=int64),)

您只需知道
RAdeccircle
已平方,无需在上一条语句中再次平方。(r^2=x^2+y^2)的可能重复项
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),)