Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [array]

Questions about Mathematica arrays, or implementing array data-type functionality, i.e, collections of regular dimensions containing elements that can be accessed by standard (computable) indices.

6
votes
4answers
120 views

Sort with assumptions

I have a list which looks like this list = {0, Subscript[x,7], -Subscript[x,3]-Subscript[x,9], -Subscript[x,9]}; and all the $x_i$'s are positive semidefinite (i....
0
votes
1answer
44 views

Part::pkspec1: The expression j cannot be used as a part specification

I want to do some stuff with symbolic arrays like this a[[j]] + a[[j + 1]] == a[[j - 1]] + a[[j - 2]] But upon declaring such an expression I get ...
1
vote
1answer
64 views

Drawing an approximate visualization of an inequality using ArrayPlot

I need to write a function that returns graphic visualization of the two-dimensional figure described with equation: $\qquad P = \{(x, y) \in R^2: 4+2x < x^2+y^2<9\}$ I have to use the n x n ...
1
vote
1answer
69 views

DefineDLLFunction returning array

I have an external "C" DLL function which returns a pointer to an byte array as well as the number of array elements (bytes) ...
4
votes
3answers
212 views

Converting a list of colors into an image

I want to manipulate colors, and merge the resulting vector and rasterize it into an image, controlling the resolution of the pixel. E.g. I tried to: But what I would like to have is an image of 3 ...
2
votes
1answer
51 views

Fast and Listable Piecewise function

I am writing a simulation where I have an array with ten columns and on the order of millions of rows, for which I need to iterate on the order of ten thousand times, making computation time a major ...
0
votes
0answers
51 views

What is the difference between an array and a list

Is there a difference in functionality between a list of lists and an array? In Python sometimes data structures are mutable or immutable. I don't see the difference in Mathematica.
2
votes
1answer
98 views

Mathematica incorrectly imports a table

I am trying to calculate the eigenvalues of a large matrix (10^4x10^4), which is formed by summing a matrix containing advective terms and a matrix containing diffusive terms. I am using the following ...
1
vote
1answer
42 views

Make a plot from data [closed]

I have two variables $x$ and $y$ satisfying, say, $y^2 + x < 1$, such that $0 \le x < 1$ and $0\le y<1$. I want to plot all the points satisfying the inequality $y^2 + x < 1$ and also show ...
0
votes
1answer
35 views

imposing conditions on an array within a function

Let's say I have the following function ...
4
votes
5answers
428 views

How to join many columns of data in array?

I have large number of columns of data. How to put in single matrix? For example, with test data of 1 x 3 matrixs ...
0
votes
1answer
79 views

Get .csv or .xlsx real data, some missing, into Mathematica and form it for curve fitting and 3D plotting

Problem: My data consists of Real values at Real $x, y$ positions. It is stored in the array-forms: comma-separated (type .csv) and spreadsheet (type .xlsx). As a Mathematica Dataset, it may be ...
5
votes
2answers
127 views

Fast element-wise division of matrix, generated from vector with `Outer`, and another matrix

m = {a, b, c}; n = {{e, r, t}, {y, u, i}, {g, h, j}}; k = Outer[Divide, m, m]; k/n gives ...
12
votes
1answer
810 views

Meaning of ## #

While looking for an answer to a different problem, I came across the following example: In[1]:= Array[Plus[##] &, {2,2}] Out[1]= {{2,3},{3,4}} Having read ...
0
votes
1answer
44 views

Derivative of sum of elements of array [closed]

I try to get derivative of sum of an array with respect to an element of the array. $$s = \sum_{i = 1}^{3}A_{i, 1}$$ Evaluate $\frac{\partial s}{\partial A_{1,1}}$ Below is the code. ...
2
votes
2answers
49 views

Counting the number of Configurations in an Array with Constraints

Consider an array $$\{a_i\}, i=1, ..., N$$ with periodic boundary condition, i.e. $i\equiv i+N$. $a_i\in \{0, 1\}$. I would like to count the number of configurations of the array $\{a_i\}$ satisfying ...
1
vote
1answer
44 views

change color of ArrayPlot

I have de following array: size=5; Initial = RandomInteger[{0, 1}, {size, size}]*2 - 1; to visualize it I use the following code: ...
1
vote
0answers
55 views

How can I modify an element of an array? [closed]

I have a simple array like this one: myArray = {1, 2, 17} At some point I want that 2 to be a 4. How can I change it?
23
votes
1answer
292 views

Which second arguments is VectorQ/MatrixQ/ArrayQ optimized for?

VectorQ and similar functions (MatrixQ, ArrayQ) treat certain second arguments specially. ...
0
votes
0answers
23 views

Plotting an element of large array is slow

I get a slow down when using ContourPlot on elements of a large array of messy expressions. That is, if fooArray has 100 elements and I plot the first 3, that's much slower than if fooArray has 3 ...
1
vote
1answer
62 views

Evaluating the 1st argument of Set

I want to assign a certain value to an element of a tensor. This element is identified by an array obtained from some evaluations, so we fix it. Here i present an oversimplified core part of my code: ...
1
vote
1answer
220 views

Tag Times in Null is Protected [closed]

I've some problems with the error mentioned in the title. Unfortunately, my code is full of subscripts so I'll show it in a photo. In this code the central aspect is to assign a scalar value to an ...
0
votes
1answer
69 views

Position for array

how does Positionwork for array? In particular if i have something like this: ...
1
vote
2answers
40 views

Change value of boundary of a multidimensional array

How can we change the value of boundary of a multidimensional Array with arbitrary rank. I tried to extract the indicies with: ...
9
votes
3answers
488 views

Removing lists with zero at any position

I want to delete the complete list within a list containing 0 at any position. I tried using: ...
10
votes
2answers
443 views

Mathematica equivalent of NumPy broadcast addition for large arrays [duplicate]

What is the Mathematica equivalent of the following Python code with the vectors' broadcast addition? ...
4
votes
2answers
241 views

Populating an array in do loop, allocating memory or not

I am doing a calculation where I have a do loop can be as long as 1 million. In each loop, I want to store a value into an array to plot afterward. In MATLAB normally I was preallocating the memory ...
2
votes
1answer
131 views

Flatten a list at some level

I wonder if is possible flatten a list at the last level without flattening at the first level, I think that isn't a good explanation so here is my code ...
0
votes
0answers
33 views

matrix perturbation general formula with random values

Is there a way to generate an arbitrary-sized diagonal matrix of variables, not numbers, in mathematica? Probably unnecessary context: For a research question I'm pursuing, I want to find general ...
4
votes
2answers
251 views

Handling arrays

Is there a way to transform a matrix in a vector, where you choose the order of the arrangement? I used ArrayReshape but this command chooses its own arrangement, ...
6
votes
2answers
143 views

How to create non-rectangular array with Array?

From the answers to this question, I learned that the recommended way to construct a symbolic sum of terms in an expression is to use Array. But I'm having a ...
4
votes
1answer
113 views

Append to a list piecewise

Is there a way to append piecewise for example list = {{1,2,3},{v,w,x},{a,b,c}} Then append a list which ...
0
votes
1answer
77 views

Loss of 1 to 1 mapping due to duplicate in Association

The main goal of this procedure is to first rotate an array of 3D coordinate leaving z untouched,finding the positions of tuples with z larger than some value, and then mapping those positions to the ...
2
votes
1answer
96 views

How to import and array of data?

I'm trying to import many files which have the same name "x.data", but they end with a extension "x_code1.data". I was trying to import all files with the routine: ...
7
votes
2answers
138 views

Constructing expressions using Sum vs Array[… Plus] vs Plus@@Table[…]

For constructing a sum of terms which are symbolic, I noticed that in addition to ...
13
votes
3answers
477 views

Convert QR code to a Nonogram puzzle

I remember there was a GCHQ puzzle where Nonogram was created to generate a QR code in 2015. It was a quite popular puzzle. I am wondering if MMA can be used to create a Nonogram from an existing QR ...
5
votes
3answers
85 views

Efficiency in array element replacement

Suppose I have two lists: ...
8
votes
3answers
110 views

Creating a random matrix of no duplicates in both row and column from a given set list of elements

Say I have a list of letters {A,B,C,D,E,F,G,H}, I want to create an $4\times 8$ array where each row must not contain duplicates and each column must also not contain duplicates. Naively writing: <...
1
vote
0answers
43 views

Mapping over array/matrix the efficient(compact) way

Update In short, I have myCAans[[1 ;; 5]] like this: {{0, 0, 0, True, 0, 0, 0, 0, True, 0, "T0", 39}, {0, 0, 0, True, 0, 0, 0, 1, True, 1, "B", 101500}, {...
6
votes
3answers
275 views

How to re-scale a matrix column and show the matrix in one line?

I have p = {{a, b, c}, {d, e, f}, {g, h, i}}; and q = p;, is it possible to combine the following 2 lines into 1 line (without <...
4
votes
1answer
55 views

Apply ParallelMap to function f over a matrix while passing as arguments the row number and the element index

I have a matrix test = { {2.5,1.4,3.3},{4,4,4},{7,3.2,9}} and a function f that requires 2 arguments, the row number and the ...
3
votes
1answer
65 views

Elegant method of arranging several aligned plots with specified empty elements

I want to display a series of plots that are aligned, but with certain array positions being empty. If I generate an array of plots like this: ...
1
vote
2answers
113 views

function fails to use local variable when it is called inside a Module

I have these two functions fun and microstep.Fun makes use of a Module construct within which I define the ...
5
votes
2answers
501 views

How to reshape an array faster?

I have a large array (arr) of size 22 X 225 X 225 and I want it to be reshaped to a size of ...
9
votes
4answers
716 views

Compare two lists and give 1 and 0 using if command

There are two lists{2,5,9,...} and {natural numbers}. I need to compare it with natural numbers and get a list with 0 and 1 if the number is present in the list, to get {0,1,0,0,1,0,0,0,1,..}
0
votes
1answer
44 views

How can I apply a matrix manipulation operation to each matrix in a list? [closed]

I have a list of matrices generated by the code ...
0
votes
0answers
34 views

Nested Lists - How to total second element by grouping first element [duplicate]

I would like to create a new list with the first element being the unique value (year) and the second element being the sum of corresponding values. Example: ...
2
votes
1answer
42 views

Combination of FromDigits and ConstantArray gives strange result [closed]

I am trying to concatenate the integers contained within my Array in order to form a single integer. For this, I am using a combination of ...
0
votes
2answers
58 views

function on a multidimensional array in Mathematica

I have a 3 dimensional array S, elements of which are labelled by S[[x,y,z]]. I want to write a function f[S,x,y,z] that given a ...
0
votes
0answers
89 views

Constraint Problem with NDSolve

I have a problem concerning an NDSolve solution, the code is the following: ...