python中reshape:
import numpy as np
a=np.array([1,2,3,4,5,6,7,8,9])
b=a.reshape((3,3))
c=a.reshape((3,3))
#c=a.reshape((3,-1)),-1代表自动补齐
print(c)
a[5]=98#或者b[1][2]=99
print(b)
print(a)
'''
[[1 2 3]
[4 5 6]
[7 8 9]]
[[ 1 2 3]
[ 4 5 98]
[ 7 8 9]]
[ 1 2 3 4 5 98 7 8 9]
可以发现python中reshape成多维矩阵首先是按行顺序
其次reshape新生成数组和原数组共用一个内存,不管改变哪个,另一个都会被影响
python中数组矩阵下标是从0开始
'''
Matlab:
%reshape(A,m,n)
%reshape(A,m,[]) []代表自动补齐
%reshape(a:mn+a,m,n)
>> A=[1 2 8 5];
>> B=reshape(A,2,2)
%{B =
1 8
2 5
%}
>> C=reshape(A,1,[])
%{C =
1 2 8 5
%}
>> D=reshape(5:29,5,5)
%{D =
5 10 15 20 25
6 11 16 21 26
7 12 17 22 27
8 13 18 23 28
9 14 19 24 29
%}
%可以看出matlab对原来数组排序是先按列
C++:Mat
#include <iostream>
#include "highgui.h"
using namespace std;
int main()
{
Mat data = Mat(20, 30, CV_32F); //设置一个20行30列1通道的一个矩阵
cout << "行数: " << data.rows << endl;
cout << "列数: " << data.cols << endl;
cout << "通道: " << data.channels() << endl;
system("pause");
return 0;
}
/* 之后补充见解
来源:CSDN
作者:该死的碳酸饮料呀
链接:https://blog.csdn.net/s36147124/article/details/103470779