最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用numpy實現(xiàn)矩陣的翻轉(flip)與旋轉

 更新時間:2021年06月03日 14:53:38   作者:patrickpdx  
這篇文章主要介紹了使用numpy實現(xiàn)矩陣的翻轉(flip)與旋轉,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

numpy.flip(m, axis=None)

Reverse the order of elements in an array along the given axis.

The shape of the array is preserved, but the elements are reordered.

把m在axis維度進行切片,并把這個維度的index進行顛倒

示例

隨機生成一個二維數(shù)組

import  numpy as np
a=np.random.randint(1,9,size=9).reshape((3,3))

[[5 8 6]
[3 1 7]
[8 7 8]]

axis=0:上下翻轉,意味著把行看成整體,行的順序發(fā)生顛倒,每一行的元素不發(fā)生改變

print(np.flip(a,axis=0))

[[8 7 8]
[3 1 7]
[5 8 6]]

axis=1:左右翻轉,意味著把列看成整體,列的順序發(fā)生顛倒,每一列的元素不發(fā)生改變

print(np.flip(a,axis=1))

[[6 8 5]
[7 1 3]
[8 7 8]]

Numpy矩陣的旋轉

使用skimage.io讀出來的圖片是numpy.darray格式,掌握numpy矩陣的旋轉與翻轉,可實現(xiàn)數(shù)據(jù)增廣(data augmentation)。

可用rot90函數(shù)實現(xiàn),例子如下:

import numpy as np
mat = np.array([[1,3,5],
                [2,4,6],
                [7,8,9]
                ])
print mat, "# orignal"
mat90 = np.rot90(mat, 1)
print mat90, "# rorate 90 <left> anti-clockwise"
mat90 = np.rot90(mat, -1)
print mat90, "# rorate 90 <right> clockwise"
mat180 = np.rot90(mat, 2)
print mat180, "# rorate 180 <left> anti-clockwise"
mat270 = np.rot90(mat, 3)
print mat270, "# rorate 270 <left> anti-clockwise"

如果mat是圖片,那么可視化效果更好。

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論

广元市| 长春市| 两当县| 凌海市| 田东县| 城步| 同心县| 本溪市| 盱眙县| 诸城市| 莱西市| 托克托县| 雷州市| 宜君县| 吐鲁番市| 虎林市| 双江| 南部县| 太谷县| 满城县| 门源| 同心县| 汝阳县| 江阴市| 连南| 星子县| 巴楚县| 江城| 台北市| 通辽市| 白玉县| 新晃| 缙云县| 涡阳县| 黄大仙区| 翁源县| 彰武县| 即墨市| 林芝县| 冀州市| 民县|