Reshapes-MATLAB-Like-Python
バージョン 1.0.0 (1.74 KB) 作成者:
Yintai
Reshape arrays row-wisely like python.
MATLAB-Reshapes-Like-Python
Reshape arrays row-wisely like python.
RESHAPE(A, new_size)
Usage:
A is an array
new_size is an array represents the shape of the new n-dimensional matrix. [new_size_1, new_size_2, ..., new_size_n] The shape have to be compatable.
It will return the reshaped array. The computation time is propotional to the number of indices of the tensor, not the number of the elements.
Examples
In MATLAB
>> a = 1:6;
>>
>> b = RESHAPE(a, [2,3])
b =
1 2 3
4 5 6
>> b = RESHAPE(a, [2,1,3])
b(:,:,1) =
1
4
b(:,:,2) =
2
5
b(:,:,3) =
3
6
>> b = RESHAPE(a, [2,3,1])
b =
1 2 3
4 5 6
>> a = RESHAPE(b, [1, 6])
a =
1 2 3 4 5 6
>>
The array is reshaped in matlab as in python, except the indices of matlab start with 1 while indices of python start with 0.
>>> import numpy as np
>>> a = np.linspace(1, 6, 6)
>>> b = a.reshape(2,3)
>>> b
array([[1., 2., 3.],
[4., 5., 6.]])
>>> b = a.reshape(2,1,3)
>>> b
array([[[1., 2., 3.]],
[[4., 5., 6.]]])
>>> b[:,:,1]
array([[2.],
[5.]])
>>> b[:,:,0]
array([[1.],
[4.]])
>>> b[:,:,2]
array([[3.],
[6.]])
>>> b = a.reshape(2,3,1)
>>> b
array([[[1.],
[2.],
[3.]],
[[4.],
[5.],
[6.]]])
>>> b[:,:,0]
array([[1., 2., 3.],
[4., 5., 6.]])
>>> a = b.reshape(1, 6)
>>> a
array([[1., 2., 3., 4., 5., 6.]])
引用
Yintai (2025). Reshapes-MATLAB-Like-Python (https://github.com/zhangyintai/MATLAB-Reshapes-Like-Python), GitHub. に取得済み.
MATLAB リリースの互換性
作成:
R2023a
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linuxタグ
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!GitHub の既定のブランチを使用するバージョンはダウンロードできません
| バージョン | 公開済み | リリース ノート | |
|---|---|---|---|
| 1.0.0 |
|
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
この GitHub アドオンでの問題を表示または報告するには、GitHub リポジトリにアクセスしてください。
