Reputation: 2081
I created the 3D array me
that contains three 2D arrays. I want to delete for example the 2nd array [:,:,2]
and copy the result to a new array called you
.
I tried deleteat!(me, :,:,2)
but it gives me an error.
me = reshape(1:(5*5*3), 5, 5, 3)
Upvotes: 3
Views: 182
Reputation: 2301
First of all, a 3-tensor is not an array of arrays, Julia has built-in N-dimensional array support.
Since you've recognized that you can't do this without copying (precisely why deleteat!()
doesn't work), the simplest way to do this is:
julia> me[:,:,[1,3]]
5×5×2 Array{Int64, 3}:
[:, :, 1] =
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
[:, :, 2] =
51 56 61 66 71
52 57 62 67 72
53 58 63 68 73
54 59 64 69 74
55 60 65 70 75
Other ways to systematically excluding index can be found at: Exclude elements of Array based on index (Julia)
Upvotes: 6