简体   繁体   中英

How to declare a binary array in numpy?

This question might be pretty simple to answer, but I had problems finding obvious answer in the numpy documentation.

What is the dtype to select when initializing a binary numpy array as follows:

array = np.zeros(8, dtype=np.int)

You can use np.bool:

array = np.zeros(8, dtype=np.bool)

output:

array([False, False, False, False, False, False, False, False])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM