You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function `wrapdims` does a bit more checking and fixing.
87
-
It will adjust the length of key vectors if it can, and their indexing if needed to match the array:
87
+
The function `wrapdims` does a bit more checking and fixing, but is not type-stable.
88
+
It will adjust the length of ranges of keys if it can,
89
+
and will fix indexing offsets if needed to match the array.
90
+
The resulting order of wrappers is controlled by `AxisKeys.nameouter()=false`.
88
91
89
92
```julia
90
93
wrapdims(rand(Int8, 10), alpha='a':'z')
@@ -98,35 +101,41 @@ axiskeys(ans,1) # 10:10:100 with indices 0:9
98
101
99
102
As usual `axes(A)` returns (a tuple of vectors of) indices,
100
103
and `axiskeys(A)` returns (a tuple of vectors of) keys.
101
-
If the array has names, then `dimnames(A)` returns them,
102
-
and functions like `axes(A, name)`give just one.
104
+
If the array has names, then `dimnames(A)` returns them.
105
+
These functions work like `size(A, d) = size(A, name)`to get just one.
103
106
104
107
Many functions should work, for example:
105
108
106
-
* Reductions like `sum(A; dims=:channel)` can use dimension names.
107
-
Likewise `prod`, `mean` etc., and `dropdims`.
108
-
109
109
* Broadcasting `log.(A)` and `map(log, A)`, as well as comprehensions
110
110
`[log(x) for x in A]` should all work.
111
111
112
-
* Transpose etc, `permutedims`.
112
+
* Transpose etc, `permutedims`, `mapslices`.
113
113
114
114
* Concatenation `hcat(B, B .+ 100)` works.
115
115
Note that the keys along the glued direction may not be unique afterwards.
116
116
117
+
* Reductions like `sum(A; dims=:channel)` can use dimension names.
118
+
Likewise `prod`, `mean` etc., and `dropdims`.
119
+
117
120
* Some linear algebra functions like `*` and `\` will work.
118
121
119
122
* Getproperty returns the key vector, to allow things like
120
-
`for (i,t) in enumerate(A.time); fun(A[i], t); ...`.
123
+
`for (i,t) in enumerate(A.time); fun(val = A[i,:], time = t); ...`.
121
124
122
125
* Vectors support `push!(V, val)`, which will try to extend the key vector.
123
126
There is also a method `push!(V, key => val)` which pushes in a new key.
124
127
125
128
To allow for this limited mutability, `V.keys isa Ref` for vectors,
126
129
while `A.keys isa Tuple` for matrices & higher. But `axiskeys(A)` always returns a tuple.
127
130
128
-
*[LazyStack](https://github.com/mcabbott/LazyStack.jl)`.stack` is now hooked up.
129
-
Stacks of named tuples like `stack((a=i, b=i^2) for i=1:3)` create axis keys.
131
+
* Named tuples can be converted to and from keyed vectors,
132
+
with `collect(keys(nt)) == Symbol.(axiskeys(V),1)`
133
+
134
+
*[LazyStack](https://github.com/mcabbott/LazyStack.jl)`.stack` understands names and keys.
135
+
Stacks of named tuples like `stack((a=i, b=i^2) for i=1:5)` create a matrix with `[:a, :b]`.
136
+
137
+
*[NamedPlus](https://github.com/mcabbott/NamedPlus.jl) has a macro which works on comprehensions:
138
+
`@named [n^pow for n=1:10, pow=0:2:4]` has names and keys.
130
139
131
140
### Absent
132
141
@@ -234,4 +243,4 @@ In 🐍-land:
234
243
[DataFrames](https://github.com/JuliaData/DataFrames.jl), only one- and two-dimensional.
235
244
Writes indexing "by position" as `df.iat[1, 1]` for scalars or `df.iloc[1:3, :]` allowing slices,
236
245
and lookup "by label" as `df.at[dates[0], 'A']` for scalars or `df.loc['20130102':'20130104', ['A', 'B']]` for slices, "both endpoints are *included*" in this.
237
-
246
+
See also [Pandas.jl](https://github.com/JuliaPy/Pandas.jl) for a wrapper.
0 commit comments