gpt4 book ai didi

julia - not 运算符 (!) 不适用于数组广播

转载 作者:行者123 更新时间:2023-12-03 15:27:00 25 4
gpt4 key购买 nike

我想知道为什么 not 运算符不使用数组广播/元素操作。例如,如果我输入

 x = Array{Any}([1,2,3,4,missing,6])
!ismissing.(x)
我收到一个错误 ERROR: MethodError: no method matching !(::BitArray{1})但如果我尝试 ismissing.(x) 它工作正常,
ismissing.(x)
#out > 6-element BitArray{1}: 0 0 0 0 1 0
并且在没有广播的情况下打字也可以作为一个整体(整个数组的一个输出)
!ismissing(x)
#out > True
所以我想知道是否有可能获得与使用“!”类似的结果。运算符(operator)。

最佳答案

您还需要广播!每个元素:

julia> x = Array{Any}([1,2,3,4,missing,6]);

julia> .!(ismissing.(x)) # the . comes before operators (!, +, -, etc)
6-element BitVector:
1
1
1
1
0
1
对于这种特定情况,您可以在广播之前否定该功能:
julia> (!ismissing).(x)
6-element BitVector:
1
1
1
1
0
1

关于julia - not 运算符 (!) 不适用于数组广播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66274939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com