Ze Chen

Comparison of Languages (II)

by language I mean programming language...

This post is devoted to numerical computations and focuses on numpy and MATLAB.


Basic Array Operations

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}{}\).

2021/1/29 22:40:43

0%

Uploaded successfully.

0%

Uploaded successfully.


0%

Uploaded successfully.

0%

Uploaded successfully.