Stack Exchange Network

Stack Exchange network consists of 174 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.

0
votes
1answer
62 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
123 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
793 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
42 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
48 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
38 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
288 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
152 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
64 views

Position for array

how does Positionwork for array? In particular if i have something like this: ...
1
vote
2answers
38 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
474 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
431 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
238 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
95 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
248 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
130 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
104 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 ...
7
votes
3answers
437 views

How to write an array of repeated numbers as a single number

Let's say we have a random number consisting of an arbitrary number of digits, such as for example 3097. This number can be represented as an array of repeated numbers with Mathematica by typing <...
0
votes
1answer
76 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
58 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
128 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
414 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
80 views

Efficiency in array element replacement

Suppose I have two lists: ...
8
votes
3answers
98 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
40 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
259 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
52 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
62 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
96 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
468 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
715 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
43 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
25 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
56 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
74 views

Constraint Problem with NDSolve

I have a problem concerning an NDSolve solution, the code is the following: ...
1
vote
2answers
46 views

How to get the correct dimension of a scalar expression?

Dimensions works pretty well with an array. Dimensions[a] Dimensions[{a}] Dimensions[{{a}}] Dimensions[{a, b}] {} {1} ...
0
votes
0answers
53 views

Array generated by loops

I have an issue making an array by for. The idea is to generate the diagonal of the array by a progression, and then replicate that value for the lower part of the array. The part that makes the ...
0
votes
0answers
32 views

3D Sparse array [duplicate]

Following the 3D matrix representation shown here Vitaliy Kaurov's answer for "Plot 3D boolean Array or matrix in Mathematica" Is it possible to use a SparseArray ...
2
votes
2answers
105 views
1
vote
2answers
38 views

How can I get a variable to be recognized as an array when computing expectation for multivariate distributions

The following expression works correctly: Expectation[ x^4, {x, y, z} \[Distributed] MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]]] But when I ...
6
votes
0answers
115 views

Sorting rows of matrix by criterion for columns

I would like to reshuffle the rows of a matrix until a criterion is met for all columns. Let us say I have a matrix $G$: ...
0
votes
1answer
61 views

How to generate a list of all lists of known objects obeying some constraints

Let PlanePartitions[m_Integer] be a certain list of objects that I'm able to produce for positive integers $m$, concretely the list of all 3d partitions of a given ...
0
votes
1answer
48 views

How to solve for points in a region of a plane? [closed]

I have three points in 3D Cartesian space: A = {-0.154, -0.246, -0.439}; B ={-0.0055, -0.3945, -0.3895}; C= {-0.154, -0.444, -0.241}; that all lie on the ...
1
vote
0answers
186 views

numerical gradient of an array

I have 2D arrays of numeric data and I would like to calculate the vector gradient of these arrays. I would like to achieve something like the 'gradient' function of MatLab: https://www.mathworks....
1
vote
0answers
35 views

Shorthand to Extend Range / Array with Elements on either side [closed]

Is there a short hand for adding a value to a vector? E.g., {.01,Range[.5,5,.5],10} gives ...