際際滷

際際滷Share a Scribd company logo
NumPy(2)
Benson
NumPy(2)
¥互丼楕拝圭宴議親W麻議耗周.
¥戻工寄楚謹S裳才ン痕塀.
¥圭宴タ輜鯀拭⊂懆吉\麻
¥淫根阻W、、電會、I/O x柊元羨~Q、児云來旗機∋云y\
麻式SC庁M吉孔嬬
NumPy(2)
(匯)芦b NumPy
(屈)R秘(import) NumPy
(眉)秀羨双c裳
(膨)双c裳議捐
(励)裳紗p核茅式児云\麻
(鎗)沫哈、俳頭、亨旗、栽禳遊峺
(鈍)view, shadow copy 才 deep copy \麻
(伊)了圷\麻
(湘)忖堪\麻
(噴)IO \麻
(噴匯)來旗掬cy
NumPy(2)
(鎗)沫哈、俳頭、亨旗、栽禳遊峺
============= ===============================
character description
============= ===============================
沫哈 圷殆議了崔,邑^沫哈辛參函誼議圷殆峙
俳頭 c沫哈載貌,圭宴酔堀紋Q沫哈議圷殆
亨旗 戻工來議圭塀輳L侭嗤議圷殆
栽 裳岻g恂栽禹鰡BY,嗤換岷才邦峠圭鮑
蛍護 裳岻g卆音揖S鰈俳護,圭塀嗤換岷才邦峠圭
蛍護
===================================================
NumPy(2)
沫哈: 圷殆議了崔
[圭隈]: 沫哈議軟泌峙 0,辛卆會f奐,賜榒扈K峙-1,卆會fp.
1)a[index_a]:x函沫哈 index_a 議圷殆
2)a[index_a:index_b]:x函Bm^g沫哈 index_a 欺 index_b+1 議圷殆
[箭 1]: a = [2,4,6,8,10,12,14,16,18,20],函誼沫哈 index_a=2
議圷殆峙.
In [1]: a = np.array([2,4,6,8,10,12,14,16,18,20])
In [2]: a[2]
Out[2]: 6
NumPy(2)
[箭 2]: a = [2,4,6,8,10,12,14,16,18,20],函誼沫哈 index_a=2
欺 index_b=5 參式 index_a=-5 欺 index_b=-1 侭議圷殆峙,.
In [1]: a = np.array([2,4,6,8,10,12,14,16,18,20])
In [2]: a[2:5]
Out[2]: array([ 6, 8, 10])
In [3]: a[-5:-1]
Out[3]: array([12, 14, 16, 18])
NumPy(2)
俳頭: 紋Q了崔議圷殆
[圭隈]: [index_s:index_e:index_c], index_s:軟兵議沫哈,index_e:
Y崩議沫哈,index_c:紋Q侯及ラ沫哈議圷殆峙.
[箭 1]: a = [2,4,6,8,10,12,14,16,18,20],軟兵沫哈 0,Y崩沫哈
 9,∨哈 2 議蔚桔議圷殆峙譲紋Q 66.
In [1]: a = np.array([2,4,6,8,10,12,14,16,18,20])
In [2]: a[0:9:2]=66
In [2]: print(a)
[66 4 66 8 66 12 66 16 66 20]
NumPy(2)
[箭 2]: a = [2,4,6,8,10,12,14,16,18,20],∬双議圷殆恂宜會.
In [1]: a = np.array([2,4,6,8,10,12,14,16,18,20])
In [2]: a[::-1]
Out[2]: array([20, 18, 16, 14, 12, 10, 8, 6, 4, 2])
In [3]: a[::1]
Out[3]: array([ 2, 4, 6, 8, 10, 12, 14, 16, 18, 20])
NumPy(2)
亨旗: L侭嗤議圷殆
[圭隈]: for i in array:,邑^筈議圭塀輳L双賜裳議侭嗤圷殆.
[箭 1]: a = [2,4,6,8,10,12,14,16,18,20],\喘亨旗輳L侭嗤議
圷殆.
In [1]: a = np.array([2,4,6])
In [2]: for i in a:
print(i)
2
4
6
NumPy(2)
[箭 2]: a = [2,4][8,10],\喘亨旗輳L侭嗤議圷殆.
In [1]: a = np.array([[2,4],[8,10]])
In [2]: for i in a:
print(i)
[2 4]
[ 8 10]
In [3]: for i in a.flat:
print(i)
2
4
8
10
NumPy(2)
栽: 裳岻g恂栽禹鰡BY
[圭隈]:
*換岷圭鮑
np.vstack(), or np.concatenate(axis = 0)
*邦峠圭鮑
np.hstack(), or np.concatenate(axis = 1)
NumPy(2)
[箭 1]: a = [2,4][6,8], b = [10,12][14,16],\喘 np.vstack(),
才 np.concatenate(axis = 0) a 才 b 恂換岷圭鮑
In [1]: a = np.array([[2,4],[6,8]])
In [2]: b = np.array([[10,12],[14,16]])
In [3]: np.vstack((a, b))
Out[3]:
array([[ 2, 4],
[ 6, 8],
[10, 12],
[14, 16]])
NumPy(2)
In [4]: np.concatenate((a, b), axis = 0)
Out[4]:
array([[ 2, 4],
[ 6, 8],
[10, 12],
[14, 16]])
NumPy(2)
[箭 2]: a = [2,4][6,8], b = [10,12][14,16],\喘 np.hstack(),
才 np.concatenate(axis = 1) a 才 b 恂邦峠圭鮑
In [1]: a = np.array([[2,4],[6,8]])
In [2]: b = np.array([[10,12],[14,16]])
In [3]: np.hstack((a, b))
Out[3]:
array([[ 2, 4, 10, 12],
[ 6, 8, 14, 16]])
In [4]: np.concatenate((a, b), axis = 1)
Out[4]:
array([[ 2, 4, 10, 12],
[ 6, 8, 14, 16]])
NumPy(2)
蛍護: 裳岻g卆音揖S鰈俳護
[圭隈]:
*換岷圭魴峺
np.vsplit(), or np.split(axis = 0)
*邦峠圭魴峺
np.hsplit(), or np.split(axis = 1)
NumPy(2)
[箭 1]: a = [2,4,6,8][10,12,14,16][18,20,22,24],\喘
np.vsplit(), 才 np.split(axis = 0) a 恂換岷圭魴峺
In [1]: a=np.array([[2,4,6,8],[10,12,14,16],[18,20,22,24]])
In [2]: np.vsplit(a, 3)
Out[2]:
[array([[2, 4, 6, 8]]), array([[10, 12, 14, 16]]), array([[18,
20, 22, 24]])]
In [3]: np.split(a, 3, axis = 0)
Out[3]:
[array([[2, 4, 6, 8]]), array([[10, 12, 14, 16]]), array([[18,
20, 22, 24]])]
NumPy(2)
[箭 2]: a = [2,4,6,8][10,12,14,16][18,20,22,24],\喘
np.hsplit(), 才 np.split(axis = 1) a 恂邦峠圭魴峺
In [1]: a=np.array([[2,4,6,8],[10,12,14,16],[18,20,22,24]])
In [2]: np.hsplit(a, 2)
Out[2]:
[array([[ 2, 4],
[10, 12],
[18, 20]]), array([[ 6, 8],
[14, 16],
[22, 24]])]
NumPy(2)
In [3]: np.split(a, 2, axis = 1)
Out[3]:
[array([[ 2, 4],
[10, 12],
[18, 20]]), array([[ 6, 8],
[14, 16],
[22, 24]])]
NumPy(2)
(鈍)view, shadow copy 才 deep copy \麻
============= ===============================
character description
============= ===============================
view 秀匯仟議裳,俐個圷殆峙厚個圻兵裳議圷
殆峙,徽俐個S業K音厚個圻兵裳議S業
shadow copy 秀匯仟議裳,俐個圷殆峙才S業厚個圻兵裳
議圷殆峙才S業
deep copy 秀匯仟議裳,俐個圷殆峙才S業K音厚個圻
兵裳議圷殆峙才S業
===================================================
NumPy(2)
view: 俐個圷殆峙厚個圻兵裳議圷殆峙,徽俐個S業K音厚個圻兵裳
議S業.
[圭隈]: b = a.view()
[箭 1]: \喘 view()秀匯仟議裳,K俐個圷殆峙才S業.
In [1]: a = np.arange(5)
In [2]: b_view = a.view()
In [3]: b_view.shape = 5,1
In [4]: b_view[0] = 999
NumPy(2)
In [5]: print('a=',a)
a= [999 1 2 3 4]
In [6]: print('b_view=n',b_view)
b_view=
[[999]
[ 1]
[ 2]
[ 3]
[ 4]]
NumPy(2)
shadow copy: 俐個圷殆峙才S業厚個圻兵裳議圷殆峙才S業.
[圭隈]: b = a
[箭 1]: \喘 shadow copy 秀匯仟議裳,K俐個圷殆峙才S業.
In [1]: a = np.arange(5)
In [2]: b = a
In [3]: b.shape = 5,1
In [4]: b[0] = 999
In [5]: print('a=',a)
NumPy(2)
a= [[999]
[ 1]
[ 2]
[ 3]
[ 4]]
In [6]: print('b=n',b)
b_view= [[999]
[ 1]
[ 2]
[ 3]
[ 4]]
NumPy(2)
deep copy: 俐個圷殆峙才S業K音厚個圻兵裳議圷殆峙才S業.
[圭隈]: b = a.copy()
[箭 1]: \喘 copy()秀匯仟議裳,K俐個圷殆峙才S業.
In [1]: a = np.arange(5)
In [2]: b_copy = a.copy()
In [3]: b_copy.shape = 5,1
In [4]: b_copy[0] = 999
NumPy(2)
In [5]: print('a=',a)
a= [0 1 2 3 4]
In [6]: print('b_copy=n',b_copy)
b_copy=
[[999]
[ 1]
[ 2]
[ 3]
[ 4]]
NumPy(2)
(伊)了圷\麻
============= ===============================
character description
============= ===============================
bitwise_and 裳圷殆茂侘市 And 荷恬
bitwise_or 裳圷殆茂侘市 Or 荷恬
invert 梓了圷函郡
left_shift 屈M崙燕幣議了圷鰈麭
right_shift 屈M崙燕幣議了圷鰉厰
===================================================
NumPy(2)
bitwise_and: 茂侘市 And 荷恬.
[圭隈]: np.bitwise_and()
[箭 1]: a = 10, b = 15,\喘 np.bitwise_and  a 才 b 恂屈M崙 and
議\麻.
In [1]: a = 10
In [2]: b = 15
In [3]: np.bitwise_and(a, b)
Out[4]: 10
NumPy(2)
bitwise_or: 茂侘市 Or 荷恬.
[圭隈]: np.bitwise_or()
[箭 1]: a = 10, b = 15,\喘 np.bitwise_or  a 才 b 恂屈M崙 or
議\麻.
In [1]: a = 10
In [2]: b = 15
In [3]: np.bitwise_or(a, b)
Out[4]: 15
NumPy(2)
invert: 茂侘市郡魏掀.
[圭隈]: np.invert()
[f苧]:
* 10 M崙議久巖DQ撹 2 M崙,K函郡,1  0,0  1.
*泌惚恷互了圷 1,燕幣蚰
*茅阻恷互了圷隠隔音,凪N了圷壅函郡,Kψ邉洋市壅恂紗 1 議嘛
*壅DQ撹 10 M崙
NumPy(2)
[箭 1]: a = 10,\喘 np.invert  a 恂屈M崙郡鰡\麻.
In [1]: a = 10
In [2]: bin(a)
Out[2]: '0b1010'
In [3]: bin(np.invert(a))
Out[3]: '-0b1011'
In [4]: np.invert(a)
Out[4]: -11
NumPy(2)
left_shift: 屈M崙燕幣議了圷鰈麭
[圭隈]: np.left_shift()
[箭 1]: a = 10,\喘 left_shift  a 議屈M崙了圷鰈麭 2 了圷.
In [1]: a = 10
In [2]: bin(a)
Out[2]: '0b1010'
In [3]: np.left_shift(a, 2)
Out[3]: 40
NumPy(2)
In [4]: bin(np.left_shift(a, 2))
Out[4]: '0b101000'
NumPy(2)
right_shift: 屈M崙燕幣議了圷鰉厰
[圭隈]: np.right_shift()
[箭 1]: a = 10,\喘 right_shift  a 議屈M崙了圷鰉厰 2 了圷.
In [1]: a = 10
In [2]: bin(a)
Out[2]: '0b1010'
In [3]: np.right_shift(a, 2)
Out[3]: 2
NumPy(2)
In [4]: bin(np.right_shift(a, 2))
Out[4]: '0b10'
NumPy(2)
(湘)忖堪\麻
¥壓 NumPy 匆嗤S謹議痕疑敏茂俔峇荷恬,初B械喘議痕.
============= ===============================
character description
============= ===============================
char.add 双M佩忖堪B俊
char.multiply 茂亢犂臨峇B俊
char.center 喜塘峺協議忖憲豢忖堪議念瘁
char.capitalize 忖堪議及匯忖銚DQ撹寄忖銚
char.title 忖堪嶄耽臨峙諜斷忖銚脅DQ撹寄忖銚
NumPy(2)
char.lower 忖堪嶄議耽忖圷脅DQ撹弌忖銚
char.upper 忖堪嶄議耽忖圷脅DQ撹寄忖銚
char.split 參峺協憲ψ峇恂蛍護撹圷殆
char.splitlines 參Q佩憲ψ峇恂蛍護撹圷殆
char.strip 卞茅圷殆議_^才Y硫議蒙協忖圷賜憲
char.join 參峺協議憲躔峺式B俊双嶄議耽圷殆忖
char.replace 聞喘仟議忖堪賜憲輒Q圷殆嶄圻云議忖堪
char.encode 忖堪DQ撹エa瘁議忖圷才憲
char.decode 忖堪M佩盾a
===================================================
NumPy(2)
char.add: 双M佩忖堪B俊
[圭隈]: np.char.add()
[箭 1]: a = I m, b= Benson,\喘 np.char.add  a 才 b 恂忖堪B俊.
In [1]: a = 'I am'
In [2]: b = ' Benson'
In [3]: np.char.add(a,b)
Out[3]: array('I am Benson', dtype='<U11')
NumPy(2)
char.multiply: 茂亢犂臨峇B俊
[圭隈]: np.char.multiply()
[箭 1]: a = Hello! ,\喘 np.char.multiply  a 恂 3 肝忖堪B俊.
In [1]: a = 'Hello! '
In [2]: np.char.multiply(a,3)
Out[2]: array('Hello! Hello! Hello! ', dtype='<U21')
NumPy(2)
char.center: 忖堪崔豢嶄g,K參峺協議憲a割壓忖堪議念瘁匯岷欺侭
O協議L業.
[圭隈]: np.char.center()
[箭 1]: a = Hello!,\喘 np.char.center 參=議憲 a 忖堪念瘁野
M撹 20 忖圷.
In [1]: a = 'Hello!'
In [2]: np.char.center(a, 20, '=')
Out[2]: array('=======Hello!=======', dtype='<U20')
NumPy(2)
char.capitalize: 忖堪議及匯忖銚DQ撹寄忖銚.
[圭隈]: np.char.capitalize()
[箭 1]: a = i am Benson.,\喘 np.char.capitalize  a 忖堪議及
匯忖銚DQ撹寄忖銚.
In [1]: a = 'i am Benson.'
In [2]: np.char.capitalize(a)
Out[2]: array('I am benson.', dtype='<U12')
NumPy(2)
char.title: 忖堪嶄議耽臨峙諜斷忖銚脅DQ撹寄忖銚.
[圭隈]: np.char.title()
[箭 1]: a = i am benson.,\喘 np.char.title  a 忖堪嶄議耽
忖議及匯忖銚脅DQ撹寄忖銚.
In [1]: a = 'i am benson.'
In [2]: np.char.title(a)
Out[2]: array('I Am Benson.', dtype='<U12')
NumPy(2)
char.lower: 忖堪嶄議耽忖圷脅DQ撹弌忖銚.
[圭隈]: np.char.lower()
[箭 1]: a = I AM BENSON.,\喘 np.char.lower  a 忖堪嶄議耽忖
圷脅DQ撹弌忖銚.
In [1]: a = 'I AM BENSON.'
In [2]: np.char.lower(a)
Out[2]: array('i am benson.', dtype='<U12')
NumPy(2)
char.upper: 忖堪嶄議耽忖圷脅DQ撹寄忖銚.
[圭隈]: np.char.upper()
[箭 1]: a = i am benson.,\喘 np.char.upper  a 忖堪嶄議耽忖
圷脅DQ撹寄忖銚.
In [1]: a = 'i am benson.'
In [2]: np.char.upper(a)
Out[2]: array('I AM BENSON.', dtype='<U12')
NumPy(2)
char.split: 參峺協憲ψ峇恂蛍護撹圷殆.
[圭隈]: np.char.split()
[箭 1]: a = i,am,benson.,\喘 np.char.split  a 忖堪參,憲
忖堪恂蛍護撹圷殆.
In [1]: a = 'i,am,benson.'
In [2]: np.char.split(a, ',')
Out[2]: array(list(['i', 'am', 'benson.']), dtype=object)
NumPy(2)
char.splitlines: 參Q佩憲ψ峇恂蛍護撹圷殆.
[圭隈]: np.char.splitlines()
[箭 1]: a = I am Benson.,\喘 np.char.splitlines  a 忖堪參Q
佩憲/n, or /r 蛍護撹圷殆.
In [1]: a = 'InamrBenson.'
In [2]: np.char.splitlines(a)
Out[2]: array(list(['I', 'am', 'Benson.']), dtype=object)
NumPy(2)
char.strip: 卞茅圷殆議_^才Y硫議蒙協忖圷賜憲.
[圭隈]: np.char.strip()
[箭 1]: a = mI am Benson.m,\喘 np.char.strip  a 忖堪議_^才
Y硫 m 忖圷卞茅.
In [1]: a = 'mI am Benson.m'
In [2]: np.char.strip(a, 'm')
Out[2]: array('I am Benson.', dtype='<U14')
NumPy(2)
char.join: 參峺協議憲躔峺式B俊双嶄議耽圷殆忖圷.
[圭隈]: np.char.join()
[箭 1]: a = Hi!, I am Benson.,\喘 np.char.join  a 忖堪嶄議耽
忖圷脅參-憲恂蛍侯式B俊.
In [1]: a = ['Hi!', 'I am Benson.']
In [2]: np.char.join('-', a)
Out[2]: array(['H-i-!', 'I- -a-m- -B-e-n-s-o-n-.'],
dtype='<U23')
NumPy(2)
[箭 2]: a = Hi!, I am Benson.,\喘 np.char.join  a 忖堪嶄議及
匯圷殆議耽忖圷脅參/憲恂蛍侯式B俊, 及屈圷殆議耽忖圷脅參#憲
恂蛍侯式B俊.
In [1]: a = ['Hi!', 'I am Benson.']
In [2]: np.char.join(['/', '#'], a)
Out[2]: array(['H/i/!', 'I# #a#m# #B#e#n#s#o#n#.'],
dtype='<U23')
NumPy(2)
char.replace: 聞喘仟議忖堪賜憲輒Q圷殆嶄圻云議忖堪.
[圭隈]: np.char.replace()
[箭 1]: a = Hi!, I am Benson.,\喘 np.char.replace  a 忖堪嶄
Hi!忖圷憲DQ撹 Hello!.
In [1]: a = ['Hi!', 'I am Benson.']
In [2]: np.char.replace(a, 'Hi!', 'Hello!')
Out[2]: array(['Hello!', 'I am Benson.'], dtype='<U12')
NumPy(2)
char.encode: 忖堪DQ撹エa瘁議忖圷才憲.
[圭隈]: np.char.encode()
[箭 1]: a = Hi!, I am Benson.,\喘 np.char.encode  a 忖堪D
Q撹エa瘁議忖圷才憲,聞喘議頁 cp500 議エa.
In [1]: a = ['Hi!', 'I am Benson.']
In [2]: np.char.encode(a, 'cp500')
Out[2]: array([b'xc8x89O',
b'xc9@x81x94@xc2x85x95xa2x96x95K'],
dtype='|S12')
NumPy(2)
char.decode: 忖堪M佩盾a.
[圭隈]: np.char.decode()
[箭 1]: a = [b'xc8x89O',
b'xc9@x81x94@xc2x85x95xa2x96x95K'],\喘
np.char.decode  a 忖堪DQ撹盾a瘁議忖憲,聞喘議頁 cp500 議エa.
In [1]: a = [b'xc8x89O',
b'xc9@x81x94@xc2x85x95xa2x96x95K']
In [2]: np.char.decode(a, 'cp500')
Out[2]: array(['Hi!', 'I am Benson.'], dtype='<U12')
NumPy(2)
(噴)IO \麻
¥壓 NumPy 匆嗤辛參岷俊ξ勅M佩x函參式議痕,初B械喘議痕.
============= ===============================
character description
============= ===============================
save 裳崛猟周嶄,険n兆.npy
load x函猟周嶄議Y創,険n兆.npy
savze 謹裳崛猟周嶄,険n兆.npz
savetxt 裳崛猟周嶄,険n兆.txt
loadtxt x函猟周嶄議Y創,険n兆.txt
===================================================
NumPy(2)
save: 裳崛猟周嶄,険n兆.npy.
[圭隈]: np.save()
[箭 1]: a = [2,4,6,8,10],邑^ np.save ∬双 a 秘欺
np_save_outfile.npy n宛嶄.
In [1]: a = np.array([2,4,6,8,10])
In [2]: np.save('np_save_outfile.npy', a)
NumPy(2)
load: x函猟周嶄議Y創,険n兆.npy.
[圭隈]: np.load()
[箭 1]: 邑^ np.load x函n宛 np_save_outfile.npy 嶄議Y創.
In [1]: np.load('np_save_outfile.npy')
Out[2]: array([ 2, 4, 6, 8, 10])
NumPy(2)
savez: 謹裳崛猟周嶄,険n兆.npz.
[圭隈]: np.savez()
[箭 1]: a = [2,4,6,8,10], b = [1,3,4,5,9]才 c = [2,14,16,18,20],
邑^ np.savez ∬双 a,b,才 c 脅秘欺 np_savez_outfile.npz n宛嶄.
In [1]: a = np.array([2,4,6,8,10])
In [2]: b = np.array([1,3,5,7,9])
In [3]: c = np.array([2,14,16,18,20])
In [4]: np.savez('np_savez_outfile.npz', a, b, c)
NumPy(2)
旋喘 np.load 迺C謹裳秘欺 np_savez_outfile.npz 議犯.
In [5]: file_data = np.load("np_savez_outfile.npz")
In [6]: file_data['arr_0']
Out[6]: array([ 2, 4, 6, 8, 10])
In [7]: file_data['arr_1']
Out[7]: array([1, 3, 5, 7, 9])
In [8]: file_data['arr_2']
Out[8]: array([ 2, 14, 16, 18, 20])
NumPy(2)
savetxt: 裳崛猟周嶄,険n兆.txt.
[圭隈]: np.savetxt()
[箭 1]: a = [2,4,6,8,10],邑^ np.savetxt ∬双 a 秘欺
np_save_outfile.txt n宛嶄.
In [1]: a = np.array([2,4,6,8,10])
In [2]: np.savetxt('np_save_outfile.txt', a)
NumPy(2)
loadtxt: x函猟周嶄議Y創,険n兆.txt.
[圭隈]: np.loadtxt()
[箭 1]: 邑^ np.loadtxt x函n宛 np_save_outfile.txt 嶄議Y創.
In [1]: np.loadtxt('np_save_outfile.txt')
Out[2]: array([ 2., 4., 6., 8., 10.])
NumPy(2)
(噴匯)來旗掬cy
¥壓 NumPy 匆嗤辛參岷俊ξ勅M佩x函參式議痕,初B械喘議痕.
============= ===============================
character description
============= ===============================
dot 裳恂ce(鳩e)
vdot 鯀迅ce(鳩e)
inner 互S業裳S貧議才e
cross 裳恂我e
outer 裳恂翌e
matmul 裳議核e
NumPy(2)
linalg.det 麻秘裳議佩双塀
linalg.solve 麻來圭殻塀議 x 盾
linalg.inv 麻裳核隈剃裳
amin 裳嶄峺協參佩賜參双議恷弌峙
amax 裳嶄峺協參佩賜參双議恷寄峙
ptp 裳嶄峺協參佩賜參双議恷寄峙-恷弌峙
percentile 裳嶄電會岻瘁參佩賜參双薺,K竃為蛍曳
議圷殆峙
===================================================
NumPy(2)
dot: 裳恂ce(鳩e).
[圭隈]: np.dot()
[箭 1]: a = [1, 2, 3],[3, 4, 5],[5, 6, 7], b = [2, 4, 6],[6,
8, 10],[10, 12, 14],\喘 np.dot 輦麻鳩e.
In [1]: a = np.array([[1, 2, 3],[3, 4, 5],[5, 6, 7]])
In [2]: b = np.array([[2, 4, 6],[6, 8, 10],[10, 12, 14]])
In [3]: np.dot(a,b)
NumPy(2)
Out[3]:
array([[ 44, 56, 68],
[ 80, 104, 128],
[116, 152, 188]])
NumPy(2)
vdot: 鯀迅ce(鳩e).
[圭隈]: np.vdot()
[箭 1]: a = [1, 2, 3],[3, 4, 5],[5, 6, 7], b = [2, 4, 6],[6,
8, 10],[10, 12, 14],\喘 np.vdot 輦麻鳩e.
In [1]: a = np.array([[1, 2, 3],[3, 4, 5],[5, 6, 7]])
In [2]: b = np.array([[2, 4, 6],[6, 8, 10],[10, 12, 14]])
In [3]: np.vdot(a,b)
Out[3]: 348
NumPy(2)
inner: 互S業裳S貧議才e.
[圭隈]: np.inner()
[箭 1]: a = [1, 2, 3],[3, 4, 5],[5, 6, 7], b = [2, 4, 6],[6,
8, 10],[10, 12, 14],\喘 np.inner 輦麻壓互S業S貧議才e.
In [1]: a = np.array([[1, 2, 3],[3, 4, 5],[5, 6, 7]])
In [2]: b = np.array([[2, 4, 6],[6, 8, 10],[10, 12, 14]])
In [3]: np.inner(a,b)
NumPy(2)
Out[3]:
array([[ 28, 52, 76],
[ 52, 100, 148],
[ 76, 148, 220]])
NumPy(2)
cross: 鯀迅我e.
[圭隈]: np.cross()
[箭 1]: a = [11, 2, 3],[13, 4, 5],[15, 6, 7], b = [2, 14, 6],[6,
18, 10],[10, 22, 14],\喘 np.cross 輦麻我e.
In [1]: a = np.array([[11, 2, 3],[13, 4, 5],[15, 6, 7]])
In [2]: b = np.array([[2, 14, 6],[6, 18, 10],[10, 22, 14]])
In [3]: np.cross(a,b)
NumPy(2)
Out[3]:
array([[ -30, -60, 150],
[ -50, -100, 210],
[ -70, -140, 270]])
NumPy(2)
outer: 鯀迅翌e.
[圭隈]: np.outer()
[箭 1]: a = [11, 2, 3],[13, 4, 5],[15, 6, 7], b = [2, 14, 6],[6,
18, 10],[10, 22, 14],\喘 np.outer 輦麻翌e.
In [1]: a = np.array([[11, 2, 3],[13, 4, 5],[15, 6, 7]])
In [2]: b = np.array([[2, 14, 6],[6, 18, 10],[10, 22, 14]])
In [3]: np.outer(a,b)
NumPy(2)
Out[3]:
array([[ 22, 154, 66, 66, 198, 110, 110, 242, 154],
[ 4, 28, 12, 12, 36, 20, 20, 44, 28],
[ 6, 42, 18, 18, 54, 30, 30, 66, 42],
[ 26, 182, 78, 78, 234, 130, 130, 286, 182],
[ 8, 56, 24, 24, 72, 40, 40, 88, 56],
[ 10, 70, 30, 30, 90, 50, 50, 110, 70],
[ 30, 210, 90, 90, 270, 150, 150, 330, 210],
[ 12, 84, 36, 36, 108, 60, 60, 132, 84],
[ 14, 98, 42, 42, 126, 70, 70, 154, 98]])
NumPy(2)
matmul: 裳議核e.
[圭隈]: np.matmul()
[箭 1]: a = [1, 2, 3],[3, 4, 5],[5, 6, 7], b = [2, 4, 6],[6,
8, 10],[10, 12, 14],\喘 np.matmul 輦麻壓核e.
In [1]: a = np.array([[1, 2, 3],[3, 4, 5],[5, 6, 7]])
In [2]: b = np.array([[2, 4, 6],[6, 8, 10],[10, 12, 14]])
In [3]: np.matmul(a,b)
NumPy(2)
Out[3]:
array([[ 44, 56, 68],
[ 80, 104, 128],
[116, 152, 188]])
NumPy(2)
linalg.det: 麻秘裳議佩双塀.
[圭隈]: np.linalg.det()
[箭 1]: a = [2, 2, 3],[3, 8, 5],[5, 6, 14],\喘 linalg.det
輦麻壓佩双塀.
In [1]: a = np.array([[2, 2, 3],[3, 8, 5],[5, 6, 14]])
In [2]: np.linalg.det(a)
Out[2]: 64.00000000000003
NumPy(2)
linalg.solve: 麻來圭殻塀議 x 盾.
[圭隈]: np.linalg.solve()
[箭 1]: a = [2, 4],[3, 5],b = [8, 14],\喘 linalg.solve 輦
麻 ax=b 議來圭殻塀議盾.
In [1]: a = np.array([[2, 4],[3, 5]])
In [2]: b = np.array([8, 14])
In [3]: x = np.linalg.solve(a, b)
In [4]: print(x)
[ 8. -2.]
NumPy(2)
linalg.inv: 麻裳核隈剃裳.
[圭隈]: np.linalg.inv()
[箭 1]: a = [2, 4],[3, 5],\喘 linalg.inv 輦麻核隈剃裳.
In [1]: a = np.array([[2, 4],[3, 5]])
In [2]: np.linalg.inv(a)
Out[2]:
array([[-2.5, 2. ],
[ 1.5, -1. ]])
NumPy(2)
amin(): 裳嶄峺協參佩賜參双議恷弌峙
[圭隈]: amin()
[箭 1]: a = [2,4,6][8,10,12][14,16,18],\喘 np.amin()輦麻
恷弌議圷殆峙,佩議恷弌峙才双議恷弌峙.
In [1]: a = np.array([[2,4,6],[8,10,12],[14,16,18]])
In [2]: print(a)
array([[ 2, 4, 6],
[ 8, 10, 12],
[14, 16, 18]])
NumPy(2)
In [3]: np.amin(a)
Out[3]: 2
In [4]: np.amin(a, 0)
Out[4]: array([2, 4, 6])
In [5]: np.amin(a, 1)
Out[5]: array([ 2, 8, 14])
NumPy(2)
amax(): 裳嶄峺協參佩賜參双議恷寄峙
[圭隈]: amax()
[箭 1]: a = [2,4,6][8,10,12][14,16,18],\喘 np.amax()輦麻
恷寄議圷殆峙,佩議恷寄峙才双議恷寄峙.
In [1]: a = np.array([[2,4,6],[8,10,12],[14,16,18]])
In [2]: print(a)
array([[ 2, 4, 6],
[ 8, 10, 12],
[14, 16, 18]])
NumPy(2)
In [3]: np.amax(a)
Out[3]: 18
In [4]: np.amax(a, 0)
Out[4]: array([14, 16, 18])
In [5]: np.amax(a, 1)
Out[5]: array([ 6, 12, 18])
NumPy(2)
ptp(): 裳嶄峺協參佩賜參双議恷寄峙-恷弌峙
[圭隈]: ptp()
[箭 1]: a = [2,4,6][8,10,12][14,16,18],\喘 np.ptp()輦麻恷
寄議圷殆峙,佩議恷寄峙才双議恷寄峙-恷弌峙.
In [1]: a = np.array([[2,4,6],[8,10,12],[14,16,18]])
In [2]: print(a)
array([[ 2, 4, 6],
[ 8, 10, 12],
[14, 16, 18]])
NumPy(2)
In [3]: np.ptp(a)
Out[3]: 16
In [4]: np.ptp(a, 0)
Out[4]: array([12, 12, 12])
In [5]: np.ptp(a, 1)
Out[5]: array([4, 4, 4])
NumPy(2)
percentile(): 裳嶄電會岻瘁參佩賜參双,K竃為蛍曳議圷殆峙
[圭隈]: percentile()
[箭 1]: a = [2,4,6][8,10,12][14,16,18],\喘 np.percentile()
輦麻為蛍曳議圷殆峙.
In [1]: a = np.array([[2,4,6],[8,10,12],[14,16,18]])
In [2]: print(a)
array([[ 2, 4, 6],
[ 8, 10, 12],
[14, 16, 18]])
NumPy(2)
In [3]: np.percentile(a, 50)
Out[3]: 10.0
In [4]: np.percentile(a, 50, 0)
Out[4]: array([ 8., 10., 12.])
In [5]: np.percentile(a, 50, 1)
Out[5]: array([ 4., 10., 16.])
NumPy(2)
Reference:
http://www.numpy.org/

More Related Content

Num py basic(2) - v01