嗨,我有这段代码,通过它我的输出采用二进制格式。
b=np.array(np.zeros((1000,4)))
for i in range(1000):
n = "{0:04b}".format(int(Y[i]))
digits = [int(x) for x in str(n)]
b[i] = digits
这给出了这样的输出:
[0, 0, 0, 1]
please ignore the commas.. read it like [0 0 0 1]---binary number.
im试图对其进行更改,以使其给出如下整数:
1
有人可以帮助我吗..如何编辑我的代码以显示整数而不是二进制数字??
答案 0 :(得分:0)
Python内置的int()
将为您做到这一点:
binary_num = ''.join(arr)
regular_num = int(binary_num, 2) # 2 is the base