Numpy 的 tan(~)
方法計算每個輸入值(以弧度為單位)的正切。
參數
1. a
| array-like
輸入數組。
2. out
| Numpy array
| optional
您可以將計算結果放入 out
指定的數組中,而不是創建新數組。
3. where
| boolean
的array
| optional
標記為 False 的值將被忽略,即它們的原始值將未被初始化。如果指定了 out 參數,行為會略有不同 - 原始值將保持不變。由於這讓許多人感到困惑,請查看下麵的示例。
返回值
包含輸入數組中每個值的正切的 Numpy 數組。
例子
基本用法
np.tan([np.pi, np.pi/ 6])
array([1. , 0.57735027])
指定輸出數組
a = np.zeros(2)
np.tan([np.pi/ 4, np.pi/ 6], out=a)
a
array([1. , 0.57735027])
在這裏,我們將結果輸出到數組 a
中。
指定布爾掩碼
np.tan([np.pi/ 4, np.pi/ 6, np.pi/ 9], where=[False, True, False])
array([45232. , 0.57735027, 0.36397023])
這裏,僅使用第二個數字進行計算,因為它在掩碼中具有相應的布爾值True
。您應該注意到 False
的值如何產生奇怪的結果 - 事實上,您應該忽略它們,因為它們是沒有實際用途的未初始化數字。
現在,如果您指定了 out
參數,而不是未初始化的值,則原始值將保持不變:
a = np.zeros(3)
np.tan([np.pi/ 4, np.pi/ 6, np.pi/ 9], out=a, where=[False, True, False])
a
array([0. , 0.57735027, 0. ])
相關用法
- Python NumPy take方法用法及代碼示例
- Python Tableau tasks.delete用法及代碼示例
- Python Tableau tasks.run用法及代碼示例
- Python Tableau tasks.get用法及代碼示例
- Python Tableau tasks.get_by_id用法及代碼示例
- Python torch.distributed.rpc.rpc_async用法及代碼示例
- Python torch.nn.InstanceNorm3d用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代碼示例
- Python torchaudio.transforms.Fade用法及代碼示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代碼示例
- Python tf.summary.scalar用法及代碼示例
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.raw_ops.TPUReplicatedInput用法及代碼示例
- Python tf.raw_ops.Bitcast用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python Pandas tseries.offsets.CustomBusinessHour.onOffset用法及代碼示例
- Python torch.special.gammaincc用法及代碼示例
- Python typing.get_type_hints用法及代碼示例
- Python tensorflow.math.xlog1py()用法及代碼示例
- Python tf.compat.v1.Variable.eval用法及代碼示例
- Python tf.compat.v1.train.FtrlOptimizer.compute_gradients用法及代碼示例
- Python tf.distribute.OneDeviceStrategy.experimental_distribute_values_from_function用法及代碼示例
- Python tf.math.special.fresnel_cos用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | tan method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。