比numpy更快吗?
我想到的是否比NP的功能更快。 ATM我正在将两个数组与NP进行比较。之后,IM浏览列表检查值[a]的位置。我认为必须有一种更快的方法,但我目前找不到。对数组进行排序是没有选项。
代码看起来像这样:
a = np.array([1, 2, 3])
b = np.array([2, 1, 8])
over = np.less(a, b)
# over = [True, False, True]
pos = np.where(over == True)[0]
# pos = [0, 2]
x = b[pos]
# x = [2,8]
i was think about if there is a faster way than the np.less functionality. Atm i'm comparing two arrays with np.less an get something like [true, true, false], after that im checking with a=np.where(x == True) to get the position of the true. After that im going through the list checking where values[a]. In my opinion there have to be a much faster way but i currently can't find on. Sorting the array is no option.
The code is is looking like this:
a = np.array([1, 2, 3])
b = np.array([2, 1, 8])
over = np.less(a, b)
# over = [True, False, True]
pos = np.where(over == True)[0]
# pos = [0, 2]
x = b[pos]
# x = [2,8]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
AS ali_sh指出,只需使用条件来获取值即可。
问题不是
np.less
的速度,而是您获得的额外步骤。所有这些几乎是速度快速的;只需要删除不必要的步骤即可。即使您想在上保存在
中的true/false结果:
As Ali_Sh pointed out, just use the condition to fetch the values.
The issue is not the speed of
np.less
but the extra steps you've got. All of which are nearly-C-speed fast; just need to remove the unnecessary steps.And even if you wanted to save the True/False results in
over
: