小编Kwo*_*olf的帖子

如何将布尔数组转换为int数组

我使用Scilab,并希望将一个布尔数组转换为一个整数数组:

>>> x = np.array([4, 3, 2, 1])
>>> y = 2 >= x
>>> y
array([False, False,  True,  True], dtype=bool)
Run Code Online (Sandbox Code Playgroud)

在Scilab中我可以使用:

>>> bool2s(y)
0.    0.    1.    1.  
Run Code Online (Sandbox Code Playgroud)

或者甚至只是乘以1:

>>> 1*y
0.    0.    1.    1.  
Run Code Online (Sandbox Code Playgroud)

在Python中是否有一个简单的命令,或者我是否必须使用循环?

python integer boolean type-conversion scilab

107
推荐指数
5
解决办法
19万
查看次数

标签 统计

boolean ×1

integer ×1

python ×1

scilab ×1

type-conversion ×1