2021-01-29

Julia, @view to prevent production of a new array

My old friend the 3d array called Pop, I want to remove columns (d2), across all of d3 when the value in the end of d1 == 1, so I have this code:

Pop[end, :, 1] .!=1

I thought adding @view in front of this would write the changes back to Pop, outwith producing an additional copy in memory. This code works fine

@view(Pop[ :, Pop[end, :, 1] .!=1, :])

but it does not alter the original 3d array called Pop. I could do

Pop = @view(Pop[ :, Pop[end, :, 1] .!=1, :])

but I believe this will create another copy in memory which I'm trying to avoid. What simple syntax have I missed? Thx. J



from Recent Questions - Stack Overflow https://ift.tt/36iZZA3
https://ift.tt/eA8V8J

No comments:

Post a Comment