兩個numpy陣列的矩陣相乘
(1). 如果兩個引數a , b a,ba,b都是2 22維的,做普通的矩陣相乘。
import numpy as np
a = [[1, 0], [0, 1]]
b = [[4, 1], [2, 2]]
np.matmul(a, b)
array([[4, 1],
[2, 2]])
(2). 如果某乙個引數是n ( n > 2 ) n(n>2)n(n>2)維的,該引數被理解為一些矩陣(引數的最後兩個維數為矩陣維數)的stack,而且計算時會相應的廣播
a = np.arange(224).reshape((2,2,4))
b = np.arange(224).reshape((2,4,2))
c = np.arange(124).reshape((1,4,2))
np.matmul(a,b)
np.matmul(a,c)
out:
[[[ 28 34]
[ 76 98]]
[[428 466]
[604 658]]]
[[[ 28 34]
[ 76 98]]
[[124 162]
[172 226]]]
描述:round() 方法返回浮點數x的四捨五入值。
語法:以下是 round() 方法的語法:
round( x [, n] )
x – 數值表示式。
n – 數值表示式,表示從小數點位數。
返回浮點數x的四捨五入值。
例項:以下展示了使用 round() 方法的例項:
#!/usr/bin/python
print "round(80.23456, 2) : ", round(80.23456, 2)
print "round(100.000056, 3) : ", round(100.000056, 3)
print "round(-100.000056, 3) : ", round(-100.000056, 3)
以上例項執行後輸出結果為:
round(80.23456, 2) : 80.23
round(100.000056, 3) : 100.0
round(-100.000056, 3) : -100.0
numpy.around(a, decimals=0, out=none)
引數解析:
a為輸入列表或矩陣;
decimals為n對輸入近似後保留小數點後n位,預設為0,若值為-n,則對小數點左邊第n位近似;
out為可選引數,一般不用,用於儲存近似返回結果。
示例:np.around([0.37, 1.64])
array([ 0., 2.])
np.around([0.37, 1.64], decimals=1)
array([ 0.4, 1.6])
np.around([.5, 1.5, 2.5, 3.5, 4.5]) # rounds to nearest even value
array([ 0., 2., 2., 4., 4.])
np.around([1,2,3,11], decimals=1) # ndarray of ints is returned
array([ 1, 2, 3, 11])
np.around([1,2,3,11], decimals=-1)
array([ 0, 0, 0, 10])
當近似的小數為5時,則前一位近似為偶數。
安裝numpy時遇到的一些問題
import sklearn.datasets.make moons時 報錯 modulenotfounderror no module named numpy.testing.nosetester 原因 numpy sklearn scipy joblib版本不相容。解決方法 將所有的包都更新到最...
svn branch merge中遇到的一些問題
拉分支的時候,選擇svn branch 在彈出的框中需要選擇目標位址,不過這個有乙個問題就是,這個目標位址不能是已經建立好的,必須至少要有一級目錄還是未建立的,比如想要拉分支到目錄branch 那你最多只能在本地建立乙個branch目錄,這個 是必須要手動輸入到 from branch 否則就會報 ...
numpy的一些用法
安裝numpy windows安裝pip即可,具體方法參考pip官網 安裝方法 pip install numpy 1.14.3 cp27 none win amd64.whl 功能介紹 ndarray ndarray具有多維性。ndarray的元素可以通過索引的方式進行訪問。在numpy中,nda...