Ze Chen## Comparison of Languages (II)

#### by *language* I mean programming language...

##### Basic Array Operations

This post is devoted to numerical computations and focuses on `numpy`

and `MATLAB`

.

**Array Creation** and **Array Transpose** In `MATLAB`

, arrays are first-class objects. With `numpy`

, however, arrays should be created with the correct constructor.

```
import numpy as np
arr = np.array([[2, 3, 5, 7], [11, 13, 17, 19]])
```

`arr`

stores now \(\begin{pmatrix}2 & 3 & 5 & 7 \\ 11 & 13 & 17 & 19\end{pmatrix}{}\).

```
arr = arr.transpose()
```

`arr`

stores now \(\begin{pmatrix}2 & 11 \\ 3 & 13 \\ 5 & 17 \\ 7 & 19\end{pmatrix}{}\).

```
arr = [2, 3, 5, 7; 11, 13, 17, 19];
```

`arr`

stores now \(\begin{pmatrix}2 & 3 & 5 & 7 \\ 11 & 13 & 17 & 19\end{pmatrix}{ }\).

```
arr = arr';
```

`arr`

stores now \(\begin{pmatrix}2 & 11 \\ 3 & 13 \\ 5 & 17 \\ 7 & 19\end{pmatrix}{}\).