Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Questions on the associative data-structure introduced in Mathematica version 10.
7
votes
Accepted
Deleting all keys that have null values
Try this:
DeleteCases[test, "", {2}]
{<|"A" -> 1, "B" -> 2|>, <|"A" -> 3, "B" -> 4, "C" -> 5|>, <|"B" -> 6,
"C" -> 7|>}
Since this is about a list of associations, the level on which to search …
5
votes
Accepted
Define an access by key ( structure[key] ) for a custom structure struct?
ClearAll[myType]
myType /: myType[data_Association][s_String] := data[[s]]
var = myType[<|"A" -> 6, "B" -> 2|>];
var["B"]
2
2
votes
Accepted
Single association: group keys together by equivalence relation and total their values
Assuming that you meant the third key of your input to be {{a1, a2}, {a1, a1}}, this might do want you ask for.
a = <|{{a1, a1}, {a2, a2}} -> 1, {{a1, a1}, {a1, a2}} -> 10, {{a1, a2}, {a1, a1}} -> 3| …
7
votes
Why association pattern unmatched when using variable
Turning my comment into an answer.
It is probably because Association has the attribute HoldAllComplete: You can see that from the fact that the last in the pattern expression stays unevaluated.
You c …
7
votes
Accepted
Permute association key and generate a sparse array
Maybe with SymmetrizedArray?
size = 4;
rank = 4;
Av = <|{1, 4, 2, 3} -> a, {2, 4, 2, 4} -> b|>;
symmetries = {
{{4, 2, 3, 1}, 1},
{{4, 3, 2, 1}, 1},
{{1, 3, 2, 4}, 1},
{{2, 1, 4, 3}, 1},
…
2
votes
Pretty print of Association with Format, how to?
This could be a way to do it. Use it without any guarantees from my side.
Unprotect[Association];
format[x_List] := "<< Very long list that we do not want to see, honestly. >>";
format[x_] := x;
Asso …
1
vote
Accepted
Flatten table into Association Thread where each cell is an association from its column and ...
Maybe it works with
energies = {{{"Column1", "SA", "SB", "SC", "SD", "PxA", "PxB", "PxC", "PxD", "PyA", "PyB", "PyC", "PyD", "PzA", "PzB", "PzC", "PzD"}, {"SA", "Es", "sssigma", 0., "sssigma", 0., "- …
1
vote
Simpler way to thread dataset values to each other
What about
Rule @@@ Values@Normal@data
?
3
votes
Merge associations with the same keys, same in a sense by user's definition
What about this?
data = <|"effect" -> {5, {2, 3}}, "effects" -> {4, {1, 3, 5}}|>;
Merge[
KeyValueMap[{key, value} \[Function] WordStem[key] -> value, data],
mergeFunc
]
<|"effect" -> {9, {1, …
7
votes
Accepted
Picking/Selecting in an association
KeyIntersection[{t1, t2}][[2]]
<|"a" -> x, "b" -> x^4, "c" -> x^6, "d" -> x^9|>
or
KeyTake[t2, Keys[t1]]
<|"a" -> x, "b" -> x^4, "c" -> x^6, "d" -> x^9|>
6
votes
Merge function performing too slowly; what can be done about it?
In some constellations, when many keys are duplicates, this can be faster by two orders of magnitude than Merge and still ten times faster than kirma's method. It keeps the keys and the values in sepa …
7
votes
Min and Max of a list of Associations
Random`Private`MapThreadMin[x]
Random`Private`MapThreadMax[x]
<|"a" -> 4, "b" -> 3, "c" -> 1|>
<|"a" -> 21, "b" -> 11, "c" -> 21|>
6
votes
How to efficiently write into PackedArrays that are stored in Associations?
This may serve as a work-around, but it feels a bit too complicated.
Based on what I learnt from Leonid Shifrin, it is possible to implement a pointer type directly in Mathematica by using a symbol w …
6
votes
Fastest way to look up in a list of Associations
You can make a lookup table for the names and use Extract:
assoc = AssociationThread[tab0[[All, "name"]], Range[Length[tab0]]];
list1 = list;
list1[[All, 1]] = Lookup[assoc, list[[All, 1]]];
r = Extr …
5
votes
Accepted
Timing: extracting from List VS extracting from Association
Only bulk access to data can show that Lists are significantly faster than Associations. …