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
1
vote
2answers
140 views

generate association based on list

a is a list {1,2,3,4} b is an association <|1->a, 2->b, 3->c, 4->d|> I am trying to write a single line of code to get b from a b=<|#->myFunction[#] &|> /@ a Here is the output: ...
27
votes
3answers
340 views

Count works differently depending on how an association was created

Bug introduced in 10.4 and fixed in 11.3.0 I create two associations, that are supposed to be exactly the same. And then I want to count the elements at the second level. And I get different results: ...
4
votes
2answers
27 views

How to Quiet an operator to avoid Query fail

This Query fail, due to divide by zero error message... <|"a" -> 1, "b" -> 0|> // Query[#a/#b &] Missing["Failed"] ...can be prevented by ...
4
votes
3answers
140 views

Opposite of Counts

I would like to reverse the effect of Counts, i.e., starting with x = <|a -> 4, b -> 2, c -> 1|> I would like ...
8
votes
1answer
337 views

Transpose fail in 11.1 Dataset

The type system underlying Dataset seems a total kludge, as soon as one issue is fixed, here it recurs in a slightly different form - and difficult to isolate in minimal examples. Here's a failure ...
3
votes
1answer
76 views

Dataset type system fail with composite keys and Infinity

In 11.1, a Dataset consisting of an Association with composite keys with an Infinity causes failure in keying-in: ...
6
votes
2answers
225 views

Function like KeyMap that combines values in case of key collisions

I am looking for a function that is similar to KeyMap in that it takes a function fun to transform each key. However, when ...
5
votes
2answers
72 views

Vectorized AssociateTo

With an Association we can update keys in place two ways: ...
1
vote
0answers
28 views

DateString doesn't evaluate within Dataset [duplicate]

[11.1] Starting with a DateObject in a Dataset: data = Dataset[<|"a" -> Now|>] ...
1
vote
1answer
55 views

Delete some elements based on the keys

Given this, ...
4
votes
2answers
286 views

Merge two database with a common key

I have two list: in one of them the name of certain compounds, and in the other one the properties of each compounds. So I want to merge them to have for each compound name the relative properties. ...
7
votes
4answers
738 views

Functional programming with Associations

Suppose I have an association where keys are dates, and values are returns of some portfolio, and I want to convert the returns to cumulative returns. Now, this can be done as follows: ...
3
votes
1answer
117 views

Import::fmterr URLExecute wont import JSON

I'm trying to perform a multiple element GET request from an alfresco database of elements. The way we have it set up is if a GET request is made with a body, it will return the elements listed in the ...
0
votes
1answer
202 views

Problem with Module, Function, Association and Dataset

I have struck a combination of the above-mentioned functions that causes evaluation to fail. I wonder whether someone can help me create a more minimal example in order to understand the issue better. ...
5
votes
1answer
207 views

MapThread and AssociateTo [closed]

I am attempting to add a key-value pair to a list of associations, but am having trouble. Minimal Example: Given the list {<| a->1 |>, <| a->2 |>}...
2
votes
2answers
351 views

Using URLFetch/URLExecute to post to an internal server

I've been looking up how to do this for a while and I haven't seen any thorough explanations, just hints. Is there like a secret repository of clearly defined Mathematica code somewhere that I cant ...
9
votes
2answers
171 views

Getting slices of a nested Association via Query

I'd like to get specific slices from a nested database-like Association through Query. Take for example this toy database of ...
3
votes
2answers
122 views

Sort Output List by Search Value

Consider the following input: ClearAll[dice, sides]; dice := 3 sides := 6 CountsBy[Times @@@ Tuples[Range[1, sides], dice], {1, sides^dice}] This gives the ...
2
votes
0answers
73 views

Problems using KeySelect for associations

I'm quite new at mathematica so hopefully this is fairly simple. I am trying to make a snowflake using a hexagonal grid. I have a list of co-ordinates pnts that ...
5
votes
2answers
229 views

How to select data of one column from a Dataset ( in this particular case )?

I use Mathematica 11.0.1 on Windows10, consider the following MWE: ...
5
votes
1answer
124 views

How can multiple kernels update a shared Association object?

In the examples below, the variable status is an Association object that is supposed to be shared by three concurrent kernels. ...
2
votes
2answers
68 views

Simplifying the values in an association

How can I simplify the expressions of the values in an association in a simple way? For example, ...
0
votes
0answers
247 views

How to change a key's value of association?

I want to write a pure function to change the key's value of an association, it must return the new association, so it can be mapped to a table of associations. The AssociateTo can change key's value ...
4
votes
2answers
105 views

Select Consecutive Association rows based on pattern

I have an association that I have already sorted on "EVDATE" and then grouped by some Keys. In this case "CONTID" and ...
5
votes
3answers
389 views

Adding key-value pairs to an association. What are the alternatives?

Given the following MWE, where: ...
4
votes
2answers
100 views

Assigning values to association in DownValues

Compare the following code: Clear[t]; t = <||>; t[2] = 1/2; t[2] with ...
18
votes
3answers
1k views

Assign names to Dataset columns

I am constructing a dataset like so: data = Dataset[AssociationThread[Keys[characterCounts], charFrequencies]] which gives me a dataset that looks like this: ...
2
votes
0answers
45 views

Repeated temporary irresponsiveness [closed]

When working with a quite big nested Association (Depth reports 6, ByteCount about 7MB), Mathematica v.11.0.1 (Win 7 64b & 32b, 8.1 64b) repeatedly becomes irresponsive, indicating "Not Responding"...
8
votes
0answers
144 views

KeyValuePattern specificity in DownValues

Bug introduced in 10.4.0 and persisting through 11.3.0 CASE:3824590 [...] Developers are discussing this behavior. [...] I will let you know when I have definite information on this. [...] ...
3
votes
1answer
112 views

How to construct an Association [closed]

I have two lists of the following form: a = {{a, b, c}, {d, e, f}, {g, h, i}} b = {{1 , 2, 3}, {4, 5, 6}, {7, 8, 9}} How do I construct an Association like this? ...
4
votes
0answers
85 views

Given a list, find Association from index to value

I have a list list = {"a","b","c",…} and I want the association <| 1 -> "a", 2 -> "b", 3 -> "c", … |> This ...
9
votes
2answers
208 views

Slicing an Association with named key span without normalizing?

Is there way to slice an Association with named key span? Span currently doesn't accept named keys: ...
2
votes
0answers
63 views

Replacement rule evaluation inconsistency in Association [duplicate]

This behavior of replacement rule seems inconsistent in Association. First, the baseline example works as intended: ...
12
votes
0answers
170 views

Unix-like reference to parent and root Association?

Is there a syntax or function to reference parent and root when querying nested Associations similar to Unix' ".." and "/", eg "cd ../../mydir". ? Here's a typical application of the root construct....
5
votes
1answer
129 views

How to update a Dynamic object when only a specific Part of an Association changes?

The following example shows three dynamic objects that all update when the value associated with the "d" key of association assoc is changed: ...
4
votes
1answer
87 views

Merging nested associations. A better way to do this? [duplicate]

Suppose I have these two associations: ...
3
votes
1answer
511 views

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

Trying to play around with Wolfram Mathematica to manipulate data as dictionaries - associative arrays. http://reference.wolfram.com/language/ref/Association.html I am looking at examples, but ...
7
votes
1answer
119 views

KeyTake, KeyDrop fail with Transpose in Dataset

I think similar to unexpected-behavior-of-keytake there are other issues with v11.0 KeyTake and (more useful) KeyDrop that show ...
3
votes
3answers
217 views

Apply function to nested associations

This seems like it should be easy but I am trying to concisely enhance some nested associations with Mathematica objects (e.g., convert things to matrices, etc) but I'm having a bit of difficulty with ...
13
votes
8answers
2k views

Reverse Lookup: getting keys from values

Lists of Rules or Associations are both a useful way of mapping between values. It also ...
7
votes
2answers
136 views

Associations of List is not printing properly in mathematica 11

<|"i1" -> {a11, a12, a13}, "i2" -> {a21, a22, a23}, "i3" -> {a31, a32, a33}|>//Dataset The above code produces the following where rows are still ...
2
votes
0answers
94 views

List, Association, and Dataset, according to what principles to choose which one to use?

List, Association and Dataset are three 'objects' that can be used to store data in MMA. So ...
2
votes
1answer
156 views

Using Case to pull Keys and Values out of a nested Association

The set up: First a helper function: Clear[values] values[m_, l_, v_] := <|"Math" -> m, "Log" -> l, "Value" -> v|> I have a nested Association of ...
3
votes
1answer
103 views

ID Swapping: Efficient use of a reference table to convert ID values

Context The rise of various bio-companies for high-throughput sequencing technology and open-source bioinformatic software suites for analysis thereof, has resulted in a equivalent rise of reference ...
16
votes
1answer
271 views

Pattern matching to a function evaluation inside an Association

I find the following behaviour deeply counter-intuitive: <|1 -> 123.456 |> /. {x_?NumericQ -> Round[x]} (* <|1 -> Round[123.456]|> *) That ...
13
votes
1answer
240 views

KeyDrop does not respect Key in V11

KeyDrop[<|a -> 1|>, Key[a]] <|a -> 1|> ...
1
vote
0answers
175 views

Matching key-value pair without converting to List in KeyValueMap

I frequently use this method with KeyValueMap in order to match and refer to named parts (ie, "myKey", "myValue") EDIT: to refer to named parts in the function <...
13
votes
3answers
653 views

How to “flatten” a nested Association?

For example, I have a nested association like this ...
5
votes
2answers
131 views

Applying KeyDrop to a String Pattern

After mining some text and computing the WordCounts, I want to KeyDrop all of the elements whose keys are not words. Is there a way to apply KeyDrop to a match string pattern or regular expression? ...
5
votes
2answers
124 views

Filtering a subset of a nested dataset

I have a nested dataset (a result of a JSON import done by Mathematica, curated for this example): ...