Convert entries of an array to a list
<p>I have numpy arrays which entries consists of either zeros or ones. For example <code>A = [ 0.  0.  0.  0.]</code>, <code>B= [ 0.  0.  0.  1.]</code>, <code>C= [ 0.  0.  1.  0.]</code> Now I want to convert them into a list: <code>L =['0000', '0001', '0010']</code>. Is there an easy way to do it?</p>

<p>You can convert each list to a string using <code>join</code> like this</p>

<pre><code>def join_list(x):
    return ''.join([str(int(i)) for i in x])

A = [0, 0, 0, 0]
B = [0, 0, 0, 1]
C = [0, 0, 1, 0]

print(join_list(A))
# 0000
</code></pre>

<p>The you can add them all to a new list with a <code>for</code> loop</p>

<pre><code>new_list = []
for l in [A, B, C]:
    new_list.append(join_list(l))

print(new_list)
# ['0000', '0001', '0010']
</code></pre>

python arrays list