python和matlab中reshape函数的区别
2017-08-15 09:03
806 查看
将一段代码从matlab改为Python, 总是出来的结果与之前matlab的结果相去甚远, 接着尝试各种方法的结果是否一致,
最后将信将疑的试了reshape, 结果声泪俱下, 真的是这个函数, google一下……
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
[/code]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[/code]
相同的代码matlab 与python出现了不同的排布方式.
2
3
4
5
6
1
2
3
4
5
6
[/code]
1
[/code]
Numpy默认是C order, Matlab是 Fortran order.
转载来源:http://blog.csdn.net/yangziluomu/article/details/51277590
最后将信将疑的试了reshape, 结果声泪俱下, 真的是这个函数, google一下……
MATLAB
>> mat = [1:12] mat = 1 2 3 4 5 6 7 8 9 10 11 12 >> reshape(mat,[3,4]) ans = 1 4 7 10 2 5 8 11 3 6 9 121
2
3
4
5
6
7
8
9
10
11
12
13
1
2
3
4
5
6
7
8
9
10
11
12
13
[/code]
PYTHON
mat = np.arange(1,13) mat array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 8f6a 12]) r = np.reshape(mat,(3,4)) array([[ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12]]) r.shape (3, 4)1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[/code]
相同的代码matlab 与python出现了不同的排布方式.
PYTHON修正代码
r = np.reshape(mat, (3,4), order="F") r array([[ 1, 4, 7, 10], [ 2, 5, 8, 11], [ 3, 6, 9, 12]])1
2
3
4
5
6
1
2
3
4
5
6
[/code]
解释
需要在python程序中指明使用Fortran order, 如np.reshape(matrix, (n,n), order="F")1
1
[/code]
Numpy默认是C order, Matlab是 Fortran order.
转载来源:http://blog.csdn.net/yangziluomu/article/details/51277590
相关文章推荐
- matlab与python 语言区别总结(1)
- python语言与MATLAB语言的区别
- Matlab与Python中find/where、reshape、eig的区别
- python图片处理和matlab图片处理的区别
- Python库numpy中的svd分解和Matlab中的svd的一点区别
- matlab与python 语言区别总结
- python中的reshape()和matlab中的reshape()区别
- Python与matlab在存储三维数组上的区别
- caffe学习笔记(13):python cv2.imread()读取图片和matlab读取图像的区别
- Python中关键字global和nonlocal的区别详解
- Python中list、tuple、dict区别
- python中__get__,__getattr__,__getattribute__的区别
- Python中单引号,双引号,3个单引号及3个双引号的区别
- python list和tuple区别
- python和matlab的语法对比
- python学习 ---- StringIO和cStringIO的区别
- [zz]Python - __getattr__() 和 __getattribute__() 方法的区别
- Python3.x和Python2.x的区别
- 如何快糙好猛地在Windows下编译CAFFE并使用其matlab和python接口
- Python学习2_Python3.x和Python2.x的区别