Mathematical representation of a multidimensional array - arrays

This might me a ridiculous question.
I created mathematical model using Python and I know that I started this from the end, but I need write mathematical equations for the documentation.
The equation has multidimensional array in it.
So my question is how to present multidimensional array in mathematical way?

If the number of dimensions in your array is one, you can represent it as a vector, or perhaps a tuple. But this almost certainly is not what you mean by "multidimensional."
If the number of dimensions is two, you can use a matrix.
If the number of dimensions is greater than two, you can use a tensor. Here is a Wikipedia link explaining a little how tensors and multidimensional arrays are related. A search will give you many more such pages. Tensors include vectors and matrices, so this is the most general solution, though vectors and matrices are much more well known.

Related

How to indicate specific slice of a 3D array in MATLAB using GPUs?

I have a 4x4x1250 matrix in MATLAB. I want to find a way to move through the 4x4 matrices slice by slice in order to find the condition of the 4x4 matrices individually.
I don't want to do it in a loop because I want to do this on the GPU and would like it to be indexed.
I saw "squeeze", but I don't think it works for 3D arrays...
I kind of want to use arrayfun, but I don't know how to indicate the specific dimension that I'm interested in.
Any ideas?
Edit: I thought the details I gave are sufficient, nevertheless:
I have a matrix A, size 4x4x1250.
I am interested in the conditions of the 1250 4x4 matrices that make up A. So lets say B = A(:,:,1).
I want to calculate cond(B), but in reality I want 1250 of these calculations.
If I do arrayfun, I don't know how to specify the specific dimension of A along which to slice.
ARRAYFUN disregards the shape of the input, and operates in a purely element-wise fashion. There's also PAGEFUN on the GPU which operates on pages of an array - however, PAGEFUN only really offers an advantage if you're using one of the functions explicitly supported - otherwise it operates in an element-wise fashion.

efficient parallel(vector) matrix-times matlab

Does anyone know how to do array matrix multiplication in matlab? i.e. I have two 3 dimensional arrays consisting of sets of matrices in the first 2 dimensions and I would like to multiply each matrix in the first array with the corresponding one in the second array. So, i.e. if
A=randn(3,3);
B=cat(3,A,A);
I would like [[operation]] such that
B[[operation]]B = cat(3,A*A, A*A)
done in efficient vector form.
Many thanks in advance.
I have used MULTIPROD from the Mathworks FileExchange for N-D array multiplication before. It is basically an extension of bsxfun to N-D arrays, and works quite nicely (and fast) - although the interface is a bit cumbersome.

Sparse matrix conversion in C

I'm trying to develop a program in C to convert a sparse matrix file into a dense matrix. From what I've read, the best approach would be the use of linked lists but I have no experience with them and haven't found a good online resource explaining the subject. I'm not looking for a quick solution but rather a website or text source that can explain how the process works so I can apply it to this project. What resources I have seen, suggest using three arrays to handle the values in the matrix (The row, column, and individual value) and two arrays for the vector (one for the row, the other for the column). Thanks!
The file format you've specified is for a dense matrix. A 10x10 matrix with 100 elements is dense. A sparse matrix has fewer than n*m elements and all "missing" elements are assumed to be 0. The point of doing it this way is so that matrices that are almost all zero (which happens in a lot of applications) will use less space. But using a sparse matrix format to store a dense matrix will use far more space than just a plain array.
One common sparse matrix file format is called MatrixMarket and it looks very similar to what you described. The first line has three values, # of rows, # of columns, # of nonzero elements (called nnz). Then you have nnz lines of the actual elements in a triplet: (row #) (column #) (value)
If your sparse matrix is in a similar format then you don't need any sparse matrix in memory. Just scan the values and fill in your dense array directly.
If you do want to have a sparse matrix in memory then there are several options for how to store it. Triplets is the easiest, and it's just an in-memory version of the MatrixMarket file. 3 arrays, or 1 array of structs.
The most common structure for linear algebra operations is Compressed Sparse Columns (CSC) or Compressed Sparse Rows (CSR). I'll let you look that up, but if you want a C implementation to play with you should look at Tim Davis' CSparse. This is also how MatLAB stores sparse matrices, Tim was one of the people who wrote that part of MatLAB.
It sounds like a linked list may not be what you're looking for, but this site offers a pretty comprehensive tutorial on the subject. It may help shed some light on whether or not it would be appropriate for your problem... Good luck!

What are some interesting/practical uses for arrays with three or more dimensions?

When using arrays I generally use only a one or two dimensional array -- very rarely three or more. I'm just kind of curious, what are some interesting/practical uses for arrays with three or more dimensions? Have you ever used an array with four or more dimensions? I had a professor in college use a six dimensional array in a program he demonstrated in class...ever had more than this?
In scientific programming it can be quite common. We just start calling these higher dimensional arrays tensors. Scalars are 0-dimensional tensors, vectors are 1-dimensional tensors, matrices are 2-dimensional tensors, and after that we just call them d-dimensional tensors (d=3,4,5,6). Dot products are then called contractions over indices.
Where are they used? I use them in some of my physics simulations. For instance, one method for simulating electrons on a lattice (regular array of sites) uses a tensor with a different set of indices for each connection to a neighboring site. In a 2D square lattice (think sites in the center of each space on a chess board), that means that each tensor has four indices, one for each neighboring site, so it is a 4-dimensional tensor.
3 dimentions in your array is not that uncommon when dealing with 3D problems, like 3D tetris or such games.

CUDA how to compare two 2D arrays?

Is there any efficient algorithm to compare two 2D arrays in CUDA as fast as possible? As a result I need a number of array fields that are equal.
Thanks in advance for any help!
For these types of operations, I'd recommend looking at the http://code.google.com/p/thrust/.
Two relevant operations which might be useful are thrust::transform to construct a boolean array and thrust::count_if to do the reduction. More efficient techniques with fancy iterators etc. are also possible. Browse around the tutorials.
If you just want the number of equal elements between the two arrays, try a reduce operation. There is an example of this on NVIDIA's site: reduction. Normal sum reductions find the sum of all elements in an array a. What you want is the sum of the expression a == b for all elements. You should look articles on CUDA reduction implementations.

Resources