Stream: helpdesk (published)

Topic: BoundsError on using array mask


view this post on Zulip Markos Kapes (Apr 24 2024 at 03:05):

I'm trying to use a2d mask as a partial reference to a 4d, like so....
glcm[i, j, mask] = 1
mask is a 512x512 Boolean Array. But it gives the error....
BoundsError: attempt to access 8×8×512×512 Array{UInt8, 4} at index [1, 1, 512×512 BitMatrix]

So I tried it with a toy example.....

begin
levels = 8
h , w = 6, 6
glcm = zeros(UInt8, (levels, levels, h, w))
a = I(6) .== 1
glcm[1, 1, a] .= 1

end

and i don't get an error..... what am I missing here?

view this post on Zulip Jakob Nybo Nissen (Apr 24 2024 at 10:40):

In the first example, you forgot the dot before the equal sign in the assignment

view this post on Zulip Markos Kapes (Apr 25 2024 at 06:08):

Thanks for catching that.... but it apparently wasn't the (only) problem... still coming up with BoundsError before it even gets to assignment....

view this post on Zulip Gunnar Farnebäck (Apr 25 2024 at 10:14):

I don't think you can do partial Boolean indexing in general. It seems like your toy example works thanks to peculiarities of the Diagonal type. For a workaround, you could try @view(glcm[i, j, :, :])[mask] .= 1.


Last updated: Nov 22 2024 at 04:41 UTC