We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [associations]

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

Filter by
Sorted by
Tagged with
7
votes
1answer
108 views

Association lookup in sub-kernel seems slow

While developing a parallel version of some code, I noticed that looking up an item in an association seemed much slower than in the serial version of the code. To show the effect, I created the ...
5
votes
2answers
150 views

How to set parts of Associations “named with” SubValues

Parts of Associations can be set with the following syntax: as = <|"a" -> 10|> <|"a" -> 10|> as["b"] = 20; as ...
9
votes
4answers
206 views

Dataset query for keys of upper levels

Say I have a Dataset like this: dat=Dataset[<|"a" -> 2, "b" -> "y", "c" -> {2, 3}|>] I want to get the keys of upper levels as elements in the ...
5
votes
3answers
130 views

Changing deep parts of expression specified by complex query

asso = <|"x" -> { <|"a" -> 5, "b" -> "y", "c" -> {5, 6, 7}|>, <|"a" -> 6, "b" -> "z", "c" -> {}|>} |> I want to ...
7
votes
1answer
165 views

How to make Cases work with associations?

Consider the following association of associations: ...
0
votes
0answers
46 views

How to pass var to Select[(#colunm == value) &] construct [duplicate]

I'm using a construct (more complex in fact as the value_ should take a list) to select some entries from an association with criteria: ...
7
votes
2answers
216 views

Map Values in 'nested' association

JSON often returns sort of 'nested' associations like so: ...
6
votes
1answer
259 views

How to filter this nested list of Association

For example, I have the following data ...
24
votes
1answer
453 views

Bug with Block & Lookup: Scope Variable Leak

After debugging a large chunk of code, I could identify this MWE. ...
4
votes
3answers
156 views

Pretty print of Association with Format, how to?

I have some assocations, containing a lot of data, lets say something like <|"x"->{... big list ...},....|> I would like to print these associations in ...
4
votes
1answer
143 views

how to count or extract Cases out of list of association that matches pattern

I have list of associations ...
4
votes
0answers
190 views

Extract a key from an Association?

I have some large nested expression containing associations and I'd like to extract the nth key inside one of them, using part syntax. Here's a tiny example: ...
2
votes
1answer
64 views

TakeLargestBy nested variable in Dataset

I would like to TakeLargestBy a nested variable in a Dataset. To be clearer, here is code to make an example dataset ...
4
votes
1answer
77 views

Merging unevaluated key/values

RuleDelayed is a supported key/value wrapper in Associations. What are general guidelines/idiomatic methods for working with ...
2
votes
0answers
67 views

Kernel crash with KeySelect and repeated keys on list of rules [closed]

After running KeySelect[{"a" -> 0, "a" -> 1}, True &] my kernel either hangs forever (possibly with the eventual warning that "the kernel is not ...
8
votes
4answers
287 views

Fill the data of an Association based on a list

Consider the following the list and association. list1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; asc = <|1 -> a, 4 -> b, 7 -> c, 10 -> d|>; I would ...
1
vote
0answers
62 views

Variance of list of associations

Bug introduced in 10.4 and fixed in 11.1 Mean can calculate the mean of a list of associations: ...
4
votes
1answer
81 views

Improving the performance of Position in a list of Associations

In my program I noticed that a line using Position is the performance bottleneck because it is executed very often. Using some dummy data and adding timing functions, it is as follows: ...
6
votes
1answer
99 views

Through[] For Association

I have an association <| a->f, b->g |> where f and g are pure functions. Is ...
8
votes
1answer
131 views

Adding metadata to non-atomic expressions in Associations and Dataset

Information and Attributes require arguments to be symbols and strings , whether built in or user-defined. there's often the ...
1
vote
1answer
140 views

What is the fastest way to delete multiple entries from a list? [duplicate]

Mathematica allows Deleting multiple objects from a list given their position. However, if I don't know their positions (finding their positions in the list is too costly if the list is long), how can ...
9
votes
3answers
490 views

Accesing keys based on position in an association

I would like to have the following simple function GetKey[] on a very large association. ...
2
votes
1answer
86 views

Efficient and fast way to extract information from multiple levels data

I have a large collection of data with multi levels. An example of the data (in Association shape) is here. The data looks like this: ...
11
votes
3answers
214 views

Convert association with list key to nested assocations

I have an association that maps {x, y} pairs to values, for example: ...
3
votes
1answer
118 views

Query from Association of Associations Dataset

I have a rather large dataset comprised of Association of Associations. For better or worse, I've converted this into a Dataset. Here is a simplified version of ...
3
votes
2answers
86 views

Creating dataset from list of ragged associations with defaults for missing keys

Given the ragged dataset in form of association of associations: ...
11
votes
3answers
853 views

Best way to handle nested Maps?

I often find myself working with lists of lists of data, gathering data, performing computations, and producing a variety of different sorts of output. Intuitively, it seems like this should be done ...
4
votes
3answers
435 views

Select dataset columns after GroupBy

Very basic question. Probably showing my ignorance, but if I have a dataset like the example in the docs ...
0
votes
1answer
77 views

Dataset with the same triples as both row and column headers

I have a list of triples and a matrix. I want to use the triples as header for row and column in a dataset so that it looks like this: But with the code I have so far it makes the wrong associations: ...
9
votes
1answer
104 views

How to efficiently write into PackedArrays that are stored in Associations?

Using Association to generate complicated data types is very comfortable, in particular if one uses those tricks from How to make use of Associations?. However, I ...
11
votes
1answer
191 views

KeyValuePattern in matching and replacement in nested associations

This case revealed I am missing something in pattern matching and evaluation in case of match, or I can't grasp it due to the busy week I have. Either way, I find this problem interesting for wider ...
7
votes
3answers
249 views

Applying a function by Key pattern, preserving Association order

Any convenient ways to apply a function to Keys that match a pattern in an Association? Method should handle: Mixture of ...
5
votes
1answer
180 views

Sum some columns in list of associations grouped by other columns

I often need to sum values in a list of Associations according to some columns in that Association. I have a way of doing it, ...
1
vote
1answer
113 views

Values expression not evaluating dynamically

I am having a problem with applying Values to a list of rules within a dynamic module. The list of rules is in the following format ...
4
votes
1answer
31 views

Merge associations always taking the value that satisfies a given test

I have associations look like this: data = {<|a -> {2, l1}, b -> {3, l1}|>, <|a -> {3, l2}, b -> {2, l2}|>} I want the result: ...
7
votes
2answers
270 views

Remove element by Key

I'm trying to remove the key and respective value from an association where the key starts with an underscore. So some association: ...
4
votes
1answer
128 views

Replacing values in an association based on keys

Let's say I have the association assoc = <|"random1" -> {a,b,c}, "random11" -> {b}|> I want to replace the values, based on something related to the ...
12
votes
2answers
348 views

Pattern matching Association in rules

I would appreciate an explanation of how Associations behave in pattern matching, especially when matching rules, and using HoldPattern. Consider the following: ...
5
votes
1answer
63 views

Performance issue of Merge function

I am using mma 11.0.1 This post is related to my previous faster way to merge data. enlightened by Edmund's answer, I found a subtle performance issue of Merge ...
3
votes
2answers
123 views

HoldFirst and Hold expression as argument

I store a reference to the association in a held expression in a variable: a=<||>; b=Hold[a]; And in the code, I want to do manipulations with the original ...
6
votes
2answers
128 views

JoinAcross question with combined keys

I would like to join associations in the following way. Say I have a dataset d1: ...
3
votes
6answers
133 views

Finding the number of $4$-tuples of consisting of digits $1$-$6$ satisfying a certain condition

I'm trying to enumerate a sample space for an experiment in which $4$ fair $6$-sided dice are rolled such that exactly $3$ of them are $5$s or $6$s. The way I understand it, the last die must be any ...
8
votes
1answer
82 views

Unexpected behavior of PreIncrement when querying associations

For reasons I won't go into here, I became curious about the what would happen should I make a query that applies PreIncrement to one key in a list of associations....
1
vote
1answer
101 views

Why can't package call imported association list?

This is question is also posted at the Wolfram site here. The files are available there as well. I have a need to make use of a list of associations for fast lookup inside a Package implementation. ...
4
votes
3answers
213 views

Find prefix of list in Association

I am trying to write some kind of demonstration for coding algorithm (for prefix codes). I have an Association that contains lists of bits (0s and 1s): ...
5
votes
1answer
103 views

How to dynamically track changes to an `Association`

Bug introduced in 10.4 or earlier and persisting through 11.1.1 CASE:3892974 Thanks for bringing this to our attention. A report has been filed with the developers. I can track changes to a ...
1
vote
0answers
43 views

Create an association from a string in unknown format (it's like JSON?)

I am trying to parse a string. The string is similar with JSON, but it's not JSON, I don't know the format name of the string, so I have to parse it manually but not to use Import. Is there any ...
5
votes
1answer
1k views

How to parse JSON

please forgive me if this is obvious, but I have some JSON: ...
4
votes
2answers
283 views

convert from a dataset to list

I have a Dataset of only 1 column to start with, and I want to StringJoin every element there. Got the error message ...
4
votes
0answers
88 views

How to get parent key in Query on Association/Dataset?

Is there a general and terse method to obtain the parent key of the current "position" in a Query of an Association/...