NumPy 的 square(~)
方法計算輸入數組中每個值的平方,即每個值 p
的 p^2
。
警告
優於平方法的 **2
如果您不需要參數 2 和 3,則隻需使用 a ** 2
即可提高性能。
參數
1. a
| array_like
輸入數組。
2. out
| Numpy array
| optional
您可以將計算結果放入 out
指定的數組中,而不是創建新數組。
3. where
| boolean
的array
| optional
標記為 False 的值將被忽略,即它們的原始值將未被初始化。如果指定了 out 參數,行為會略有不同 - 原始值將保持不變。
返回值
如果 a
是標量,則返回標量,否則返回 NumPy 數組。
例子
基本用法
a = np.array([1, 3, 5])
np.square(a)
array([ 1, 9, 25])
相關用法
- Python NumPy squeeze方法用法及代碼示例
- Python sqlite3.Connection.text_factory用法及代碼示例
- Python sqlite3.Connection.enable_load_extension用法及代碼示例
- Python math sqrt()用法及代碼示例
- Python sqlite3.Connection.iterdump用法及代碼示例
- Python sqlite3.Cursor.executescript用法及代碼示例
- Python sqlite3.Connection.create_collation用法及代碼示例
- Python sqlite3.threadsafety用法及代碼示例
- Python sqlite3.Connection.row_factory用法及代碼示例
- Python sqlite3.complete_statement用法及代碼示例
- Python NumPy sqrt方法用法及代碼示例
- Python sqlite3.Connection.create_function用法及代碼示例
- Python sqlite3.Connection.create_aggregate用法及代碼示例
- Python sqlite3.Cursor.connection用法及代碼示例
- Python sqlite3.Cursor.executemany用法及代碼示例
- Python sqlite3.Connection.backup用法及代碼示例
- Python sqlite3.connect用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
- Python scipy.signal.windows.tukey用法及代碼示例
- Python scipy.stats.mood用法及代碼示例
- Python str.isidentifier用法及代碼示例
- Python sklearn.metrics.fbeta_score用法及代碼示例
- Python scipy.fft.ihfftn用法及代碼示例
- Python scipy.stats.normaltest用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | square method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。