【发布时间】:2021-04-18 17:02:24
【问题描述】:
我有一个 3D 数组,并且基于使用或运算符“|”的一个“行”中的值,我想替换不同行中的值。我试图建立一个 mwe,这里是:
# create new array
Pop = fill(Int8(3), 1, 3, 4)
# change values in one row of array
Pop[:,:,2] = [5,6,7]
# change values in second row of array
Pop[:,:,4] = [9,10,11]
# attempt conditional substitution, if element-wise value of Pop[:,:,2] equals either 6 or 7, then substitute the corresponding element wise (across row in dimension 3) for 8
Pop[:,:,2] == 6|7 Pop[:,:,3] .= 8
# to produce this end result
Pop[:,:,3] = [3,8,8]
Pop
我在替换的语法中遗漏了一些东西。谢谢。 J
【问题讨论】:
标签: arrays julia conditional-operator