0

I have a numpy array

a = [void(b'\x0A\x00\x01\x02'),
     void(b'\x0B\x02\x03\x04'),
     void(b'\x0C\x07\x03\x04')
    ]

I want something like b'\x0A\x00\x01\x02\x0B\x02\x03\x04\x0C\x07\x03\x04'

Right now I am doing it using loop

result = bytearray()
for b in a:
   result += bytearray(b)

Is there any numpy kind of way to do it, so that it becomes fast.

1
  • b''.join(bytearray) works with ists and array. Commented May 1, 2021 at 21:00

1 Answer 1

1

If you are working with numpy arrays, the easiest would probably be to call the tobytes() method.

from numpy import void 

a = [void(b'\x0A\x00\x01\x02'),
     void(b'\x0B\x02\x03\x04'),
     void(b'\x0C\x07\x03\x04')
    ]

np.array(a).tobytes()

Output:

b'\n\x00\x01\x02\x0b\x02\x03\x04\x0c\x07\x03\x04'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy 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.