我试图在我的绘图中提取虚线、虚线和虚线曲线上方的值的数量。你知道吗
我可以随时观察超过这些曲线范围的点的数量,但我不想在这种方法中冒任何错误的风险。你知道吗
首先,这些曲线由我在代码中调用的质量变量和距离变量定义Escape_Velocity
。这是我制作的班级简介的一部分。你知道吗
import numpy as np
import NFW_Profile as NFW
h0 = 0.704
NFWc12 = NFW.Profile(c=12.5, z=0.0, h=h0)
nfwEsc = NFWc12.Escape_Velocity(Mass, Radius)
在我的绘图中,曲线是基于这个函数的,在这里我选择一个任意的Mass
值,而Radius
被输入一个np.linspace
值。你知道吗
图中的值来自我对数据集的分析,我们可以调用
RadVel
是y轴值“径向速度”,而Dist
是x轴值“银河中心距离”。你知道吗
关键的一点是,这两个元素数组的维数相同,它们可以相互索引。例如,第20个索引值RadVel
对应于第20个索引值Dist
。你知道吗
所以我的计划是从
Mass
的任意值Dist
中获取元素Escape_Velocity
RadVel
值(对应于馈送给Escape_Velocity
的元素)大于Escape_Velocity
值,则它将计数。你知道吗如果Escape_Velocity
大于相应的RadVel
值,则不计算。你知道吗
import numpy as np
import NFW_Profile as NFW
h0 = 0.704
NFWc12 = NFW.Profile(c=12.5, z=0.0, h=h0)
def UnboundSubhalos(mass, Dist):
Vesc = NFWc12.Escape_Velocity(mass, Dist)
PosValues = [i for i in RadVel if i => Vesc.all()]
NegValues = [i for i in RadVel if i <= -Vesc.all()]
return len(PosValues) + len(NegValues)
就我所知,你想找到在非线性函数定义的区域之外的红点的数量,你称之为
Escape_Velocity
,红点有x-位置和y-位置,分别存储在数组Dist
和RedVal
中,按顺序排列,这样红点的位置(x,y)=(Dist[n], RedVel[n])
。另外,它看起来像(你对UnboundSubhalos
的定义表明,Escape_Velocity
定义的虚线是围绕RedVel = 0
对称的,也就是说,你实际上想要找到绝对值RedVel
大于Escape_Velocity
的红点的数量。你知道吗在这种情况下,您可以简单地执行以下操作:假设
Escape_Velocity
是一个可以向其传递数组的函数,您可以为数组Dist
的每个元素找到Escape_Velocity
,并将其存储在数组esc_vel = Escape_Velocity(Mass, Dist)
。否则,必须使用Dist
元素上的循环来计算这些值。从您的代码中,我可以假设Escape_Velocity
给出一个正值,即RedVal
正值处的虚线。然后数组outside_dots = np.abs(RedVel) >= esc_vel
包含True
对于虚线包围的区域之外的每个点,以及False
对于内部的每个点。然后np.sum(outside_dots)
给出所需的外部点数。你知道吗以下代码的工作方式如下所述:
相关问题 更多 >
编程相关推荐