这篇文章主要介绍“numpy中如何实现数组转置”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“numpy中如何实现数组转置”文章能帮助大家解决问题。
代码如下:
In [15]: arr1 = np.arange(20) In [16]: arr1 Out[16]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) In [17]: arr2 = arr1.reshape((4,5)) In [18]: arr2 Out[18]: array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19]]) In [19]: arr3 = arr2.T In [20]: arr3 Out[20]: array([[ 0, 5, 10, 15], [ 1, 6, 11, 16], [ 2, 7, 12, 17], [ 3, 8, 13, 18], [ 4, 9, 14, 19]]) In [21]: np.dot(arr3,arr2) Out[21]: array([[350, 380, 410, 440, 470], [380, 414, 448, 482, 516], [410, 448, 486, 524, 562], [440, 482, 524, 566, 608], [470, 516, 562, 608, 654]])
最新评论