1

I have a binary string "list" as input and want it to be saved as matrix of binaries which I then can use for logical operations (params coming as sys.argv[x]).

Example:

python3 k n matrixpython3 2 2 1101S101S111S1000

Should become a matrix (2D Array, numpy array, whatever) where I can make XOR, AND etc operations.So something like that:

[[1101, 101], [111, 1000]]

There are heaps of manuals about binaries in the Internet, but none which really fits what I am trying to do here.

askedSep 14, 2021 at 15:36
Hemmelig's user avatar

1 Answer1

1

You can try the following. Given your string, it seems thatS is the delimiter between your binary strings. So split on them and simply reshape using numpy

import numpy as npn = 2k = 2s = '1101S101S111S1000'tokens = s.split('S')np.array(tokens).reshape(n,k)

which yields

array([['1101', '101'],       ['111', '1000']], dtype='<U4')
answeredSep 14, 2021 at 15:41
Clock Slave's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.