Skip to content

Code in README no longer works #127

@tlnagy

Description

@tlnagy

The last example in the readme:

B = AxisArray(randn(100,100,100), :x, :y, :z)
Itotal = sumz = 0.0
for iter in eachindex(B)  # traverses in storage order for cache efficiency
    I = B[iter]  # intensity in a single voxel
    Itotal += I
    sumz += I * iter[axisdim(B, Axis{:z})]  # axisdim "looks up" the z dimension
end
meanz = sumz/Itotal

doesn't work under Julia 0.6. It gives a bounds error:

ERROR: BoundsError
Stacktrace:
 [1] getindex(::Int64, ::Int64) at ./number.jl:38
 [2] macro expansion at ./REPL[4]:4 [inlined]
 [3] anonymous at ./<missing>:?

I believe this is due to eachindex returning a single value instead of a tuple. This is likely because it is using fast linear indexing instead of Cartesian indexing. What would the updated version of this code look like? @timholy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions