8
votes
4answers
252 views

Fast method to select matrix elements based on a vector of positions

There is an operation for which I have long wanted to find a better solution. Let: a be a matrix of dimensions $m\times n$ ...
1
vote
3answers
39 views

Collect the lists

I have a list of lists from which I pick out the positions of the number 1 and then print out these positions for each list. I am having some trouble collecting what I am printing into a list / matrix ...
2
votes
2answers
133 views

Binarizing a matrix

I have an image with a few bright pixels with the remaining ones very dark. The difference is in orders of magnitude. I want to binarize this matrix (corresponding to the image) making all values ...
2
votes
3answers
95 views

Speeding Up Replacing of Labels in Large Matrix?

I am Mathematica novice and am trying to find a fast way to replace labels in some rather large matrices (512x512 or 1024x1024) that have resulted from segmenting images with WatershedComponents or ...
0
votes
0answers
53 views

deleteduplicates Delete elements of a list [duplicate]

I have a math problem about Mathematica, I am looking help from you. I hope that you could help me. The Math Problem: list= { {0,0,1},{1,0,0},{0,1,0} ,{1,2,3}}; ...
3
votes
2answers
208 views

All possible pairs of two items

I have 4 different items {1, 2, 3, 4}. I want to obtain all possible pairs of two of the items. I have written: ...
1
vote
1answer
57 views

Inverting matrix of unknown size

I have a matrix that has a variable number of columns and rows (but it is always square). The matrix is: $$ \Gamma = \begin{bmatrix} \Theta & 0 & 0 & 0 & T & 0 & R_j \\ ...
8
votes
8answers
667 views

Replace interior of matrix with zeros

I have f.e. the following square matrix: ...
1
vote
1answer
47 views

references in a nested matrix

I have a nested matrix n: ...
1
vote
0answers
70 views

How to sequentially select, from a large set of tuples (of matrices), those with a certain property

I'm interested in finding a computationally efficient way for selecting all tuples of matrices which have a certain property. The property I'm interested in is that I want the column sum, of f[the ...
5
votes
2answers
99 views

Comparison Operation for Nested Matrices

I have a nested matrix n as bellow ...
4
votes
6answers
384 views

Insert all elements from one matrix into another

I have two matrices $A$ and $B$ which are the same size. Each element of $A$ is a list of numbers. Each element of $B$ is just a number. How do I insert each element of $B$ into the corresponding list ...
0
votes
1answer
59 views

Matrix operations performed with column-vectors

We have 3 matrices: m1, m2 and b. We want to apply matrix operations (dot or sum) in a ...
1
vote
1answer
109 views

Check every list element for appearance

I'm used to MATLAB so this might be a stupid question but Mathematica is freaking me out. I have a big matrix with the following format: ...
6
votes
4answers
359 views

Generating an Ulam spiral

An Ulam Spiral is quite an interesting construction, revealing unexpected features in the distribution of primes. Here is a related topic with one answer by Pinguin Dirk, who has provided one ...
2
votes
1answer
44 views

Complement for a Matrix

In a matrix, there are some non-zero elements same as: aA= Also, there is a list such as: list = {a, b, c, d, e, f, g, ii, jj, kk}; I want to access to ...
4
votes
3answers
374 views

Efficient matrix / array generation

What is the most efficient way of generating the following matrix? $\left( \begin{array}{ccccc} 1 & 0 & 1 & 0 & 1 & 0 & 1 & \dots\\ \frac{1}{2} & \frac{1}{2} & 0 ...
0
votes
0answers
77 views

mdifying a code for nested matrices

I have a matrix such as: ...
3
votes
6answers
312 views

How can I construct a distance table?

I have a list of city names (of arbitrary length), f.e. c = {"BAL", "NYC", "LAS", "AUS"}; and the distances between them : ...
1
vote
3answers
118 views

Working with nested matrices

I have a matrix: A = {{a, b}, {c, d}} But each its element, itself, is another matrix too. ...
0
votes
1answer
60 views

Swapping rows and columns in matrix [closed]

If I have an array like the following $\left( \begin{array}{ccc} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array} \right)$ How can I swap the rows and columns, so it is ...
1
vote
1answer
74 views

Matrix and string variable

There are $100$ .dat data files which contain numerical parameters. ...
2
votes
2answers
121 views

Building adjacency matrix from set data

I have two sets: games and players. Players pick their games. As such I will have data say g1={p1,p3,p5},g2={p2,p4},g3={p2,p3,p5}. My interest though is to build the connections among players because ...
0
votes
1answer
84 views

Select positive value from a vector

I am wondering how to pick out the positive Omega value from soln, and make these positive values into a row vector. I know how ...
1
vote
2answers
103 views

How to drop the identical rows and columns of a matrix?

I'm currently trying to find a way to eliminate from a square matrix of generic dimension the duplicate (up to sign) rows and columns, obtaining a smaller dimensional matrix. I searched around here ...
2
votes
1answer
134 views

Find positions where two matrices differ

I have two matrices A and B of identical dimensions. What's the simplest (shortest) way to find the indices of differing ...
2
votes
1answer
132 views

Multiple swapping of rows and columns

m={{a, b, c, p}, {d, e, f, x}, {g, h, k, z}, {u, v, w, y}}; I want to swap 1st and 2nd rows by 4th and 3rd rows respectively. And then, swap 1st and 2nd columns ...
3
votes
1answer
115 views

Plotting with ColorFunction -> GrayLevel - no black

This is probably a fairly trivial question, yet I have been unable to find an answer - help would be much appreciated! :) I am trying to plot a 28 x 28 matrix (tabulated data given here), containing ...
3
votes
3answers
208 views

Finding a better way to define a matrix

I first defined a 171x171 matrix containing only zeros and then replaced 18 specific rows with nonzero entries. The other $153$ rows will be average of $2$ of the existing $18$ rows. Rows $2$ ...
5
votes
1answer
153 views

How to combine matrix with array without cycles?

I am new to Mathematica. And I'm sorry for my English. I have created a matrix ($6 \times 4$) and an array ($1 \times 4$). I want to get another matrix that will have the first element from the array ...
0
votes
1answer
83 views

Populating an array with outputs of a function [closed]

I have searched, but didn't find much help on my issue. I have an optical physics problem that I'm working on .. ...
1
vote
2answers
110 views

Manipulating sparse array elements

Suppose I have two sparse arrays ...
10
votes
1answer
180 views

Drop selection of columns from a ragged array

I have an application where I need to drop some arbitrary list of columns from a ragged array (where of course the shortest array rows have at least all the specified columns). E.g., given a ragged ...
9
votes
8answers
335 views

Fast way to get positions of “boxed” array elements?

Given a 2D array (arbitrary numeric / evaluates to numeric elements, simplified for examples, and can be arbitrary dimensions so long as the operation makes sense, I'm working with 2K X 2K in my ...
1
vote
1answer
240 views

How can you convert a matrix back into a list of lists?

It is very simple in Mathematica to convert a list of lists into a matrix: all you need to do is apply the //MatrixForm function to it and voila. Is it possible ...
0
votes
3answers
133 views

Implementing nested subtotals

Inserting a nested subtotal in a spreadsheet is a facility that Excel performs very well. But if a subset of this facility can be implemented in MMA for a table which needs it the hassle of its ...
1
vote
3answers
330 views

How to expand the size of the matrix automatically?

I have a matrix in 2x2 a ={{x, y}, {z, u}} I want to expand this matrix 3x3 b ={{x, y, y}, {z, u, x}, {z, x, u}} 4x4 ...
1
vote
1answer
429 views

Contracting with Levi-Civita (totally antisymmetric) tensor

I have an array $v_{ijk}$ which is effectively a rank-$3$ tensor with dimensions $3\times3\times3$, and I need to contract it with $e^{ijk}$, i.e. evaluate $v_{ijk} e^{ijk}$ (see Einstein ...
2
votes
3answers
137 views

Join matrix based on conditions

Given the following matrix: ...
5
votes
3answers
269 views

Question about Map and Total

Suppose I have a list and I want to generate a new list, such that $$ NewList[index] = \sum_{index \neq j}^{NumOfElts} \frac {1}{ \lvert OldList[index]-OldList[j] \rvert ^2 } $$ Can I do it using ...
0
votes
1answer
65 views

Produce a 1-dimensional list of all unique matrix elements

We have some symbolic matrix m, e.g. m={{1, x, 4 x + y},{0, x y + 4x, 4x},{7 x, x, 4x + x y}} and we want to produce as output a list of all the unique elements ...
6
votes
7answers
1k views

How to select all elements above the main diagonal of matrix?

How to select all elements above the main diagonal of matrix? I need to create a list of them.
1
vote
2answers
106 views

How to create automatically some matrices for symbolic manipulation?

I want to create in an automatic way some matrices to do symbolic calculations with them. They look like these: $$ \left( \begin{array}{cccc} a & 0 & b & 0 \\ 0 & 1 & 0 & 0 ...
10
votes
3answers
324 views

Zero-dimensional matrices

In a recent Mathematica project, $(n \times 0)$- and $(0 \times n)$-dimensional matrices have suddenly become a frustratingly common edge case for me. For instance, consider the following two ...
12
votes
6answers
600 views

Elegantly split a matrix into positive and negative parts?

I have a matrix $M$ of real components, and I want to split it into two matrices $M^+$ and $M^-$ of the same dimensions as $M$, where $M^+$ contains the positive components of $M$ (the remaining ...
2
votes
1answer
351 views

Calculate mean square displacements for different particles from a excel file

I have the particle movement data in the following format: ...
1
vote
2answers
109 views

Add a column to a matrix as a function of the other columns

I was wondering if its possible to add a column to a matrix by a formula that uses all other columns, like this: ...
0
votes
3answers
416 views

Find the number of nonzero elements

How do you find the number of elements in a matrix that are non-zero. For instance, the following matrix has 5 nonzero elements. ...
0
votes
1answer
188 views

Performing matrix multiplications with a list

I have a question in regards to PseudoInverse. I have $A$, an $n\times 2$ matrix, and when I want to compute $(A^T A)^{-1}A$, by using ...