# All Questions

**22**

votes

**2**answers

51502 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

2656 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...

**283**

votes

**9**answers

50977 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...

**90**

votes

**2**answers

42038 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:
...

**44**

votes

**4**answers

12982 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.
...

**449**

votes

**19**answers

1280065 views

### How to define a 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:
T...

**327**

votes

**6**answers

84523 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',...

**251**

votes

**56**answers

251771 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 ...

**28**

votes

**1**answers

1327 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...

**78**

votes

**8**answers

196418 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...