# All Questions

**21**

votes

**2**answers

49461 views

### Convert matrix to 3-column table ('reverse pivot', 'unpivot', 'flatten', 'normalize')

I need to convert the Excel matrix FIRST in the table LATER:
FIRST:
P1 P2 P3 P4
F1 X
F2 X X
F3 X X
F4 X X
LATER:
F P VALUE...

**11**

votes

**1**answers

2391 views

### How do I compose a rotation matrix with human readable angles from scratch?

The one thing that has always hindered me from doing 3D programming is failing to understand how math works. I can go along with math fine in programming flow using methods and functions, then its all...

**278**

votes

**9**answers

49681 views

### How can I index a MATLAB array returned by a function without first assigning it to a local variable?

For example, if I want to read the middle value from magic(5), I can do so like this:
M = magic(5);
value = M(3,3);
to get value == 13. I'd like to be able to do something like one of these:
value...

**88**

votes

**2**answers

39743 views

### Reshape three column data frame to matrix ("long" to "wide" format)

I have a data.frame that looks like this.
x a 1
x b 2
x c 3
y a 3
y b 3
y c 2
I want this in matrix form so I can feed it to heatmap to make a plot. The result should look something like:
...

**42**

votes

**4**answers

12513 views

### Generate a matrix containing all combinations of elements taken from n vectors

This question pops up quite often in one form or another (see for example here or here). So I thought I'd present it in a general form, and provide an answer which might serve for future reference.
...

**428**

votes

**19**answers

1193759 views

### How to define two-dimensional array in python

I want to define a two-dimensional array without an initialized length like this :
Matrix = [][]
but it does not work...
I've tried the code below, but it is wrong too:
Matrix = [5][5]
Error:
...

**317**

votes

**6**answers

79219 views

### Transpose/Unzip Function (inverse of zip)?

I have a list of 2-item tuples and I'd like to convert them to 2 lists where the first contains the first item in each tuple and the second list holds the second item.
For example:
original = [('a',...

**248**

votes

**56**answers

244430 views

### How do you rotate a two dimensional array?

Inspired by Raymond Chen's post, say you have a 4x4 two dimensional array, write a function that rotates it 90 degrees. Raymond links to a solution in pseudo code, but I'd like to see some real world ...

**27**

votes

**1**answers

1236 views

### Linear indexing, logical indexing, and all that

We are used to different forms of indexing in Matlab:
standard (using integers along each dimension),
logical (using logical values),
linear (using a single index to traverse an array with more than...

**77**

votes

**8**answers

181880 views

### Memory management / cannot allocate vector of size n Mb

I am running into issues trying to use large objects in R. For example:
> memory.limit(4000)
> a = matrix(NA, 1500000, 60)
> a = matrix(NA, 2500000, 60)
> a = matrix(NA, 3500000, 60)
Erro...