numpy.unpackbits学习

unpackbits函数可以把整数转化成2进制数。

import numpy as np

a = np.array([[2], [7], [23]], dtype=np.uint8)
b = np.unpackbits(a, axis=1)
print("a",a)
print("b",b)

输出结果:

"C:\Program Files\Anaconda3\python.exe" D:/pycharmprogram/learn/numpy_learn/unpackbits_learn.py
a [[ 2]
 [ 7]
 [23]]
b [[0 0 0 0 0 0 1 0]
 [0 0 0 0 0 1 1 1]
 [0 0 0 1 0 1 1 1]]

Process finished with exit code 0
官方文档

你可能感兴趣的:(numpy)