本文簡要介紹 python 語言中  numpy.can_cast  的用法。
- 用法:- numpy.can_cast(from_, to, casting='safe')
- 如果可以根據轉換規則在數據類型之間進行轉換,則返回 True。如果 from 是標量或數組標量,則如果標量值可以在沒有溢出或截斷的情況下強製轉換為整數,則也返回 True。 - from_: dtype、dtype 說明符、標量或數組
- 要從中轉換的數據類型、標量或數組。 
- to: dtype 或 dtype 說明符
- 要轉換為的數據類型。 
- casting: {‘no’, ‘equiv’, ‘safe’, ‘same_kind’, ‘unsafe’},可選
- 控製可能發生的數據類型轉換。 - ‘no’ 表示根本不應該轉換數據類型。 
- ‘equiv’ 表示隻允許更改字節順序。 
- ‘safe’ 意味著隻允許可以保留值的強製轉換。 
- ‘same_kind’ 表示隻允許安全類型轉換或類型中的類型轉換,如 float64 到 float32。 
- ‘unsafe’ 表示可以進行任何數據轉換。 
 
 
- out: bool
- 如果可以根據轉換規則進行轉換,則為真。 
 
 - 參數:- 返回:- 注意:- 例子:- 基本示例 - >>> np.can_cast(np.int32, np.int64) True >>> np.can_cast(np.float64, complex) True >>> np.can_cast(complex, float) False- >>> np.can_cast('i8', 'f8') True >>> np.can_cast('i8', 'f4') False >>> np.can_cast('i4', 'S4') False- 鑄造標量 - >>> np.can_cast(100, 'i1') True >>> np.can_cast(150, 'i1') False >>> np.can_cast(150, 'u1') True- >>> np.can_cast(3.5e100, np.float32) False >>> np.can_cast(1000.0, np.float32) True- 數組標量檢查值,數組不檢查 - >>> np.can_cast(np.array(1000.0), np.float32) True >>> np.can_cast(np.array([1000.0]), np.float32) False- 使用鑄造規則 - >>> np.can_cast('i8', 'i8', 'no') True >>> np.can_cast('<i8', '>i8', 'no') False- >>> np.can_cast('<i8', '>i8', 'equiv') True >>> np.can_cast('<i4', '>i8', 'equiv') False- >>> np.can_cast('<i4', '>i8', 'safe') True >>> np.can_cast('<i8', '>i4', 'safe') False- >>> np.can_cast('<i8', '>i4', 'same_kind') True >>> np.can_cast('<i8', '>u4', 'same_kind') False- >>> np.can_cast('<i8', '>u4', 'unsafe') True
相關用法
- Python numpy chararray.ndim用法及代碼示例
- Python numpy chebyshev.chebsub用法及代碼示例
- Python numpy chararray.nbytes用法及代碼示例
- Python numpy chebyshev.chebdiv用法及代碼示例
- Python numpy copy用法及代碼示例
- Python numpy chararray.setflags用法及代碼示例
- Python numpy chararray.flat用法及代碼示例
- Python numpy chararray.strides用法及代碼示例
- Python numpy chebyshev.cheb2poly用法及代碼示例
- Python numpy chararray.view用法及代碼示例
- Python numpy chebyshev.chebx用法及代碼示例
- Python numpy chebyshev.chebmul用法及代碼示例
- Python numpy char.strip用法及代碼示例
- Python numpy c_用法及代碼示例
- Python numpy cross用法及代碼示例
- Python numpy chebyshev.chebroots用法及代碼示例
- Python numpy copysign用法及代碼示例
- Python numpy char.upper用法及代碼示例
- Python numpy chararray.imag用法及代碼示例
- Python numpy chararray.base用法及代碼示例
- Python numpy chararray.flatten用法及代碼示例
- Python numpy chararray.copy用法及代碼示例
- Python numpy clip用法及代碼示例
- Python numpy char.count用法及代碼示例
- Python numpy char.chararray用法及代碼示例
注:本文由純淨天空篩選整理自numpy.org大神的英文原創作品 numpy.can_cast。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
