【发布时间】:2019-12-07 14:36:22
【问题描述】:
我尝试使用np.empty 使用False 初始化Boolean 数组,
init_arr = empty(5)
init_arr.fill(False)
但我得到了
array([0., 0., 0., 0., 0.])
然后我创建一个pd.Series,
dummy_ser = pd.Series(data=init_arr)
这就是为什么
0 0
1 0
2 0
3 0
4 0
我尝试使用 False 作为其初始化值来初始化具有不同长度的布尔系列。我想知道最好的方法是什么。
我正在使用Python 3.5.2 和Numpy 1.15.4。
【问题讨论】:
-
使用
np.zeros(5, dtype=bool)。
标签: python python-3.x pandas numpy