日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【图像处理opencv】_numpy基本操作

發(fā)布時間:2025/4/5 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【图像处理opencv】_numpy基本操作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

目錄

1 三個重要屬性

2 創(chuàng)建矩陣

3 矩陣轉換

4 最大值、最小值、平均值

5 數(shù)學運算

6 元素獲取


1 三個重要屬性

A.dtype :?data? type? 即A的數(shù)據(jù)類型,常見有float型、uint8型和float32型

A.shape :即A的形狀,比如2×2型,3×3型

A.ndim:n dimension 即A的維度,比如2維,3維等等?

2 創(chuàng)建矩陣

np.array([[1]])

np.uint([1])

np.arange(2,10,2)

np.linsapace(0,2*pi,100)

A=np.zeros((4,3),dtype=np.uint8)

B=np.ones((2,2),dtype=np.float32)

I=np.eye(4)

I2=np.identity(6)

C=np.random,randint(0,10,(4,4))

在jupyter編程中查看某個函數(shù)具體用法:光標定位到該函數(shù)中,按快捷鍵Shift+Tab

np.arange()方法---創(chuàng)建一個規(guī)定步長的矩陣

介紹:

Docstring: arange([start,] stop[, step,], dtype=None, *, like=None)Return evenly spaced values within a given interval.

舉例

np.linspace() 方法---創(chuàng)建一個等間隔矩陣

介紹:

Signature: np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0) Docstring:Return evenly spaced numbers over a specified interval.

舉例

?np.zeros()方法---創(chuàng)建0矩陣

介紹:

zeros(shape, dtype=float, order='C', *, like=None)Return a new array of given shape and type, filled with zeros.

舉例:

?np.eye()方法---創(chuàng)建對角線為1的矩陣,1的位置可通過k的值來移動

介紹

Signature: np.eye(N, M=None, k=0, dtype=<class 'float'>, order='C', *, like=None) Docstring: Return a 2-D array with ones on the diagonal and zeros elsewhere.

?舉例

?np.identity()方法---創(chuàng)建一個單位矩陣

介紹:

Signature: np.identity(n, dtype=None, *, like=None) Docstring: Return the identity array.

舉例:

?np.random.randint()方法---創(chuàng)建一個隨機矩陣

介紹

Docstring: randint(low, high=None, size=None, dtype=int)Return random integers from `low` (inclusive) to `high` (exclusive).

舉例

3 矩陣轉換

A.reshape()

A.flatten(), A.ravel()

A.T

A.transpose()

np.hstack([A,B]) , np.vstack([A,B])

A.reshape()方法---改變矩陣形狀

介紹

Docstring: a.reshape(shape, order='C')Return s an array containing the same data with a new shape.

舉例:

?A.flatten()方法---拉平矩陣(會導致矩陣降維成向量)

介紹Docstring: a.flatten(order='C')Return a copy of the array collapsed into one dimension.

舉例:

?A.ravel() 方法---拉平矩陣,與A.flatten()區(qū)別在于flatten()是復制,而ravel()是引用

介紹

Docstring:a.ravel([order])Return a flattened array.

舉例:

?B.T()方法---矩陣轉置

舉例:

?B.transpose()---矩陣轉置

介紹

Docstring: a.transpose(*axes)Returns a view of the array with axes transposed.

舉例:

?np.hstack([A,B])方法---將A、B矩陣水平疊加

介紹:

Signature: np.hstack(tup) Docstring:Stack arrays in sequence horizontally (column wise).

舉例:

?np.vstack([A,B])方法---將A,B矩陣垂直疊加

介紹:

Signature: np.vstack(tup) Docstring:Stack arrays in sequence vertically (row wise).

舉例:

4 最大值、最小值、平均值

A.max()

A.min()

A.mean()

np.max()

np.min()

np.mean()

這個很好理解,直接看例子

對整個數(shù)組運算:

對數(shù)組內的某一行或某一列進行運算(行:axis=0,列:axis=1):

5 數(shù)學運算

np.power(A,2)

np.sqrt()

np.log() , np.log2() , np.log10()

A*x , A@x

A.dot(x)

np.power(A,2)方法---將矩陣A內的每個元素平方

舉例:

?np.sqrt(B)---將B矩陣開方

舉例

?np.log() , np.log2() , np.log10()---對矩陣內的每個元素做對數(shù)運算(np.log()默認以e為底)

舉例

?A* x---矩陣A與x對位元素相乘,注意:如果矩陣形狀不一樣,則會自動復制元素不全成相同形狀的矩陣后再運算

舉例:

?A@ x , A .dot(x)---矩陣A與矩陣x的矩陣乘法

舉例

6 元素獲取

直接看例子

這是B矩陣

?對B矩陣做下面操作

??

總結

以上是生活随笔為你收集整理的【图像处理opencv】_numpy基本操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。