Questions tagged [data-structures]

Questions on using or implementing more or less common data structures such as linked lists, structs, trees, tries, heaps etc. in Mathematica.

Filter by
Sorted by
Tagged with
2
votes
2answers
19 views

Format table output

I'm trying to make a quick code to give me coordinates of some circles to be read in AUTOCAD. When I use the format "Table" or ...
5
votes
4answers
265 views

Threading data on TimeSeries

Say I have two TimeSeries: x = TimeSeries[{2, 4, 1, 10}, {{1, 2, 4, 5}}] y = TimeSeries[{6, 2, 6, 3, 9}, {{1, 2, 3, 4, 5}}] x has a value at times: 1,2,4,5 y ...
7
votes
2answers
341 views

How to import .txt file with missing data?

I have a .txt file that looks like this (direct copy from the file): ...
1
vote
1answer
54 views

How to join N datasets with common headers?

I am new to Dataset. I'm trying to join many datasets, naively trying to use Join, but I think I'm not using it correctly, or ...
8
votes
1answer
168 views

Most efficient method for export/import of non-traditional tensor-style dimensions of matrices/tables/lists-of-lists-of-lists(-of lists)?

Hello World! (I did it for my first answer, so it only feels proper...I'm not nostalgic, you are!) OKAY, here we go! Let's start off with the good-stuff, here's my code, made relatively arbitrary, ...
7
votes
1answer
102 views

Implementing core data structures

Data structures are your friend. Using the right data structure in the right place means better performance and less work on the programmer's part. This poses a problem in Mathematica, of course, ...
6
votes
2answers
417 views

Convert a huge txt-file into a dataset

My friend has this huge txt-log of sea levels. He wants to organize it into a dataset. After importing it this file a used StringSplit to separate it into rows, then to singular elements ...
0
votes
0answers
33 views

Segment tree implementation

I want to implement a segment tree visualization. I was looked for implementation in WL but didn't find. Before I'm implementing it by myself, maybe anyone knows about some implementation that will be ...
0
votes
1answer
127 views

How can I translate some JavaScript code into Mathematica code? [closed]

I am a programmer and would like to understand another field outside of the procedural thinking of if-else and for. I would ...
12
votes
1answer
461 views

Pascal records and Mathematica programming

Background: "experienced" Pascal-programmer (DOS-era, never got into OOP) proud owner of Mathematica ver 11.2 have used Mathematica for years to do my share of number crunching and plotting to ...
13
votes
6answers
239 views

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

I have an arbitrary ragged nested list-of-lists (a tree) like A = {{a, b}, {c, d}, {{{e, f, g, h, i}, {j, k, l}}, m}, n}; Its structure is given by the rules <...
4
votes
2answers
154 views

Converting from “matrix” data into “coordinate” data

Say I have data which looks like data1 - this is "matrix" like data (is there a better descriptor?). The data looks like a matrix, and at each point in the matrix, ...
3
votes
0answers
84 views

Approximate Nearest Neighbors in Mathematica?

Is there any support for Approximate Nearest Neighbors (ANN) in Mathematica or third-party packages? I'm looking for a good implementation of locality sensitive hashing for applications where ...
3
votes
1answer
69 views

What's the best way to import such dataset?

https://www.ocr.org.uk/Images/400305-large-data-set-lds_1-h630-2018-h640-2018-2019-pre-release-data-mei.xlsx What's the best way to import such dataset? I have tried to use ...
7
votes
0answers
63 views

Substitute for Association inside Compile?

Associations are not compilable, so I’m looking for a workaround to this. That is, I need a mutable hashtable-like data structure with fast key value lookups ...
4
votes
1answer
77 views

Local Storage of Periodically Collected Data (without using DataDrop)

I would like to take periodic measurements (e.g. noise levels and temperature in my office from a Raspberry Pi, etc.), say, every minute and have a long-reaching record of this similar to Stephen's ...
9
votes
1answer
614 views

Tree-like data sets with efficient storage and retrieval

Most probably this is going to be a duplicate, sorry. I found too many questions/answers here about tree-like structures, and still could not locate what I want. It is a followup of my previous ...
13
votes
1answer
254 views

Data re-structuring by Thread

Thread can do this Thread[{a, {b, c, d}}] {{a, b}, {a, c}, {a, d}} But when above ...
5
votes
3answers
183 views

ByteCount on Function

I was comparing RAM and CPU efficiency for List, Rule, Association, Function. The following code ...
3
votes
1answer
92 views

Get the dimensions from the SparseArray properties

In the sparse matrix, we have a list of properties: specified elements, dimension, default, and density. I am interested in getting this data without calculating them again. For an example, the ...
1
vote
1answer
113 views

SparseArray: accesing nonzero row and column entries

I have an enormous $m\!\times\!n$ sparse matrix $d$ with $l$ nonzero entries, stored as d=SparseArray[{{i1,j1}->w1,...,{il,jl}->wl},{m,n}];. How do I access ...
0
votes
1answer
55 views

Given a data set, how to do the following

Please help in executing the following problem in Mathematica: I have the following set:$A=\{1, 2,3,4,5,6,7,8,9,10\}$ (my actual data has more than 10 points). I need to do the following three steps: ...
1
vote
1answer
118 views

Dynamically update of Association

I try dynamically to add new keys and update the values of existing keys in given dataset (Association). I implement this by the following code: ...
0
votes
1answer
50 views

Delete duplicates and sort a list of sets separately? [closed]

I have a set where it has three subsets. I want to have each element of each subsets appears only once, sorted, but the order of subsets does not change. For example: I want to get from $$ \{\{5,2,2,3\...
1
vote
2answers
112 views

Select several values in nested associations

I have nested associations like this: ...
2
votes
0answers
51 views

Create Association from Expression

I have a set of algebraic expressions of a certain form, and I would like to make them into Associations in a specified way. My expressions are formed of two heads, ...
1
vote
3answers
80 views

Simple implementation of a multi-part ratio data structure

A multi-part ratio would be an expression of the form: $e_1:e_2:e_3:\cdots:e_n$ It would have the following properties: When the expressions are natural nos, they can be evaluated to be $$\frac{...
3
votes
0answers
76 views

HDF5 does not support string?

I did a simulation for Baccarat. So some results are saved like this. ...
3
votes
0answers
40 views

Possible to add a “Heading” for the columns in HDF5 format?

A similar post was found here, but it's not using MMA. A small test to export HDF5 file, ...
0
votes
1answer
49 views

determine the structure of Data in sum of two subsets Modulus $n$

I wrote a code below to determine the cases when two subsets of a set $\mathbb{Z_n}=\{0,1,2,\ldots,n-1\}$ are added together element by element (without removing the multiplicity) in $\mathbb{Z_n}$ ...
5
votes
4answers
420 views

count the pairs in a set of Data

I have a list of Data, e.g., list1={0, 1, 1, 1, 1, 2, 2, 3, 3} list2={0, 1, 1, 1, 1, 2, 2, 3, 3, 0} and I want to get as an output ...
0
votes
0answers
73 views

How to organize code for simulating many ODEs?

I have a large model with many variables (about a hundred) and many differential equations (non-linear). What is the best way to handle a system this size in Mathematica? Note that I am not asking ...
5
votes
3answers
205 views

Multi-coloured tree plot

I am trying to create a multi-coloured tree plot (Mathematica 9) where each branch is coloured according to its parent node value. For example, for a tree plot with three nodes, n1, n2 and n3, coming ...
5
votes
2answers
132 views

How to Label only Certain Vertices in a Network Based on Eigenvector Centrality?

Using the Following Network: footballNetwork = ExampleData[{"NetworkGraph", "AmericanCollegeFootball"}]; Graph[footballNetwork, VertexLabels -> "Name"] I ...
11
votes
3answers
202 views

Support for low-complexity (compressible) lists

By "low-complexity list" I mean a list like the following: lcl = {17, 17, 17, 17, 17, 21, 21, 21, 21, 21, 21, 21, 21, 11, 11, 11, 11, 11, 11, 11} ...
2
votes
0answers
55 views

Data structure for finding pairs of matrices under constraint

PROBLEM DESCRIPTION Given three positive integers k, n1, n2, I have a list of matrices matrices = Tuples[Range[0,k], {n1,n2}] ...
3
votes
3answers
114 views

Building matrix from relational data

I'm new to Mathematica, coming from Python, and I'm having a hard time trying to build a matrix from relational data. The data looks like this: ...
7
votes
3answers
177 views

How to disallow the application of functions outside a white list?

In an earlier post I described a special kind of list (actually, a special kind of multiset) that can be represented more efficiently with a structure like this: ...
20
votes
3answers
773 views

How to implement a discrete data representation?

I'm currently working with large datasets of "discrete data". Each of these is a multiset of real numbers of the form $kS + B$, where $k$ is an integer, and $S$ (the "scale") and $B$ (the "bias") are ...
14
votes
1answer
855 views

How to use classical data structure in Mathematica

As a C programmer, I have used Mathematica for a month. In this process, I discovered that some problems cannot be solved via the built-ins, owing to lacking of data structure like ...
28
votes
1answer
741 views

How to use the iterator in Mathematica

I find the Mathematica has the iterator data structure. We can build some iterators like this: Constant iterator GeneralUtilities`ConstantIterator[5] Key ...
3
votes
2answers
443 views

Convert between list of 3D coordinates and 2D array

I have a dataset that I import from a csv file. It's a rectangular array of values, with the first row and first column specifying the x and y coordinates. I want fit this data to a 2D function using <...
6
votes
6answers
164 views

List structure transformation

How to transform a list as {{x,y},{a,b,c,d,e}} into the form of {{x,y,a},{x,y,b},{x,y,c},{x,y,d},{x,y,e}} elegantly, ...
0
votes
1answer
56 views

How does one create getter methods that depend on a variable (besides its argument)?

In the (as always) insigthful answer by Leonard Shifrin to this MMA SE post https://mathematica.stackexchange.com/questions/52393/how-to-make-use-of-associations ...
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 ...
1
vote
3answers
87 views

Clustering with a certain number of members

Is it possible to find exact number of clusters with exact numbers of members in each cluster? Something like this: ...
6
votes
2answers
657 views

How to efficiently implement Disjoint Set/Union Find data structure?

The data is a list of lists (sets), where all the elements are distinct. There are basically two operations. Find the position that contains a certain element. (And fast accessing the set with this ...
5
votes
4answers
746 views

Is *.dat file suitable for storing high (>2) dimensional matrix?

The typical process goes as first one exports a numerical matrix mat Export["test.dat",mat,"Table"] and then imports it back ...
4
votes
1answer
161 views

Create tree association using table

Suppose I have a table like the following (This example is simplified, actual table is much larger), it is read from external files: ...
1
vote
0answers
43 views

Looking for a package for data on (sparse) uniform grids

I have large amounts of sparse 2d and 3d "volumetric" data, i.e. fixed data associated with positions in a uniform (integer coordinate) grid. I think of it as partial function $$f: \mathbb Z^n \to D.$...