Skip to main content
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
Results tagged with
Search options answers only not deleted user 4999

Questions on the associative data-structure introduced in Mathematica version 10.

11 votes
Accepted

Apply a function row- and columnwise

If we change dt to: dt = Dataset@<| "Arizona" -> <|"1801" -> 60, "1802" -> 1530, "1803" -> 100, "1804" -> 665|>, "Kansas" -> <|"1801" -> 1160, "1802" -> 415, "1803" -> 825, "180 …
Michael E2's user avatar
  • 245k
10 votes

Pattern matching Association in rules

One way to fix the OP's problem is to evaluate the associations in the patterns: Cases[assocRuleList, HoldPattern[<||> :> _ // Evaluate]] (* {<||> :> "zero"} *) Cases[assocRuleList, HoldPattern[<|" …
Michael E2's user avatar
  • 245k
9 votes

How to make arbitrary transpositions of associations and datasets

If you factor a permuation perm into a product of cycles of the form $(j\ k)$ with $k=j+1$, then the permuation can be effected by Query and Transpose. Functions: adjacentCycles[perm] (* factors per …
Michael E2's user avatar
  • 245k
7 votes

Reverse Lookup: getting keys from values

There's a certain elegance to: GroupBy[assoc, Identity, Keys] (* gives all keys for a given value *) GroupBy[assoc, Identity, First@*Keys] (* gives first key for a given value *) GroupBy[as …
Michael E2's user avatar
  • 245k
6 votes

List[...] + Association[...], or Association[...] + List[...], when does the order matter?

It's probably a bug related to packed arrays: <|"a" -> 10, "b" -> 10, "c" -> 10|> + Developer`ToPackedArray[{1, 2}] (* {<|"a" -> 11, "b" -> 11, "c" -> 11|>, <|"a" -> 12, "b" -> 12, "c" -> 12|>} *) …
Michael E2's user avatar
  • 245k
5 votes

Replace Missing[Unmatched] with zero

A couple of alternatives: assoc = <|"key" -> "2009-ABCDE", "ActuarialEPI" -> 26603.6, "ReportedEP" -> 28535., "ReportedLI" -> 0., "ELI" -> 25619.3, "DLI" -> 25619.3, "EstimatesEP" -> Missing[ …
Michael E2's user avatar
  • 245k
5 votes
Accepted

Unexpected behavior with Derivative and a function parameters defined via an Association

Why is the result Missing["KeyAbsent", 2] + Derivative[1][z[2]][y] Heads are evaluated first. The head of Derivative[0, 0, 1][func][x, 2, y] is Derivative[0, 0, 1][func], which yields the followin …
Michael E2's user avatar
  • 245k
5 votes
Accepted

Why AssociateTo does not work when Association is inside a list?

Further, I think a complete example would exhibit what happens to the source associations ode1 etc., namely that ODEs is changed but not ode1. … If you prefer working strictly with associations, you could modify the definition of setupDiffEq or add a definition like setupDiffEq[a_?AssociationQ] := setupDiffEq@Normal@a. …
Michael E2's user avatar
  • 245k
4 votes
Accepted

Average length (in words) of paragraphs in document

How picky are you about what counts as a word?: ExampleData[{"Text", "PrideAndPrejudice"}]; assoc = Association@MapIndexed[First@#2 -> # &, StringSplit[%, "."]]; WordCount /@ assoc // Total // Absol …
Michael E2's user avatar
  • 245k
4 votes
Accepted

How to map or import list of lists as associative array (dictionary)

Like this? AssociationThread @@ Transpose@data (* <|"7A37D069" -> "Copper", "6D2C07C7" -> "Autograph"|> *) The data in the comment below can be made into an Association as follows: Association …
Michael E2's user avatar
  • 245k
3 votes
Accepted

How do I thread an Association?

Something like this? network[n_List] := MapThread[ (<|"w" -> Table[RandomVariate[NormalDistribution[]], #2, #1], "b" -> Table[RandomVariate[NormalDistribution[]], #2]|> &), {Most@n, R …
Michael E2's user avatar
  • 245k
3 votes

How to swap keys and values of an association?

I suppose AssociationThread[Values@assoc, Keys@assoc], but it's not invertible if the values are not distinct. Also Association@KeyValueMap[#2 -> #1 &, assoc] with the same caveat.
Michael E2's user avatar
  • 245k