Numpy 哪里有 Julia 代码的功能?
Numpy where functionality for Julia code?
我阅读了 的答案,但还没有看到答案 (ifelse) 如何为用户提供 numpy.where 的所有功能。我在下面发布了示例代码:
A = [0.0 0.9 0.0 0.99 0.0]
a = 1:length(A)
#-v- produces [0 1.0 0 1.0 0] as expected, but how to get the index values?
b = ifelse.(A .- 1.0 .> -1.0, 1.0, 0 )
#-^- how to get the array [0.9 0.99]? How to remove all zeros from an array?
除了使用 for 循环之外的任何解决方法,我们将不胜感激。
我猜您正在寻找 np.where(cond)
的功能?就是 findall(A .> 0)
.
要获取数组 [0.9, 0.99]
,我会使用 logical indexing:A[A .> 0]
.
可能避免分配掩码数组会更快,所以
filter(x -> x>0, A)
我阅读了
A = [0.0 0.9 0.0 0.99 0.0] a = 1:length(A) #-v- produces [0 1.0 0 1.0 0] as expected, but how to get the index values? b = ifelse.(A .- 1.0 .> -1.0, 1.0, 0 ) #-^- how to get the array [0.9 0.99]? How to remove all zeros from an array?
除了使用 for 循环之外的任何解决方法,我们将不胜感激。
我猜您正在寻找 np.where(cond)
的功能?就是 findall(A .> 0)
.
要获取数组 [0.9, 0.99]
,我会使用 logical indexing:A[A .> 0]
.
可能避免分配掩码数组会更快,所以
filter(x -> x>0, A)