Mas*_*n87 5 python numpy type-conversion
我有一个 uint8 类型的变量(它只有两个值,0 和 1),我想用 -1 替换零。我是否必须首先将此变量转换为 int64 (或任何允许负数的整数数据类型)?如果是这样,我怎样才能实现它?
你不需要 int64。int8 应该可以。将 uint8 转换为 int8 :
import numpy as np
x = np.uint8(-1) # -1 does not exist in this coding, this is just a test
x
> 255
np.int8(x)
> -1 # eureka
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22076 次 |
最近记录: |