【发布时间】:2020-01-28 00:59:20
【问题描述】:
import numpy as np
txor=np.array([1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 1,
1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0,
0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1])
def chunker_list(seq, size):
return (seq[i::size] for i in range(size))
spl2=[]
spl=list(chunker_list(txor, 20))
#spl2=int('1010101',2)
#print(spl)
for i in spl:
spl1=((i))
spl2.append(spl1)
#print(spl2)
join=[]
for r in spl2:
test_list=str(r)
# printing result
test_list = [''.join(test_list[ : ])]
join.append(test_list)
res=str((join))
在此我在 spl2 中生成了一个数据,就像
[[1, 0, 1, 0, 1], [0, 1, 1, 0, 1], [0, 0, 0, 1, 0], [1, 1, 0, 0, 0], [1, 0, 1, 1, 1], [0, 0, 0, 1, 1], [1, 0, 1, 1, 0], [1, 1, 0, 1, 0], [0, 1, 1, 0, 0], [1, 1, 0, 0, 1], [0, 0, 1, 0, 1], [0, 1, 0, 0, 0], [0, 1, 1, 1, 1], [0, 1, 1, 0, 0], [1, 1, 1, 1, 1], [1, 0, 0, 1, 0], [0, 1, 0, 1, 1], [0, 1, 1, 0, 1], [0, 1, 0, 0, 1], [0, 1, 0, 0, 1]]
想要这种形式的这些spl2数据
[['10101'],['01101'],['00010'],...... 这样我就可以将上述数据集转换为十进制。如果可能,还要将 bin 写入 dec 代码:)
【问题讨论】:
-
"如果可能,也将 bin 写入 dec 代码 :)" => Stackoverflow 不是代码编写服务。到目前为止,您尝试过什么?
-
我说如果可能的话..我自己做吧。'bin to dec'
标签: python-3.x numpy binary