深入 NumPy 陣列

給 MATLAB 使用者的 Python

Justin Kiggins

Product Manager

在 NumPy 陣列上計算

print(radius)
[[1, 2, 3]]
type(radius)
 <class 'numpy.ndarray'>
area = np.pi * (radius ** 2)
print(area)
[3.14159265 12.56637061 
28.27433388]
Operation Operator
加法 +
減法 -
乘法 *
除法 /
乘冪 **
給 MATLAB 使用者的 Python

NumPy 陣列間的運算

type(revenue)
<class 'numpy.ndarray'>
print(revenue)
[[100, 114, 96, 120]]
type(cost)
<class 'numpy.ndarray'>
print(cost)
[102. 104. 101. 102.]
profit = revenue - cost
print(profit)
[-2. 10. -5. 18.]
給 MATLAB 使用者的 Python

摘要 NumPy 陣列中的資料

import numpy as np

np.mean(revenue)
107.5

一些常用的 NumPy 函式:

  • np.min() 傳回陣列中的最小值
  • np.max() 傳回陣列中的最大值
  • np.sum() 傳回陣列中所有值的總和
給 MATLAB 使用者的 Python

一起來練習吧!

給 MATLAB 使用者的 Python

Preparing Video For Download...