Copying bytes in Python from Numpy array into string or bytearray
问题 I am reading data from an UDP socket in a while loop. I need the most efficient way to 1) Read the data (*) (that's kind of solved, but comments are appreciated) 2) Dump the (manipulated) data periodically in a file (**) (The Question) I am anticipating a bottleneck in the numpy's "tostring" method. Let's consider the following piece of (an incomplete) code: import socket import numpy nbuf=4096 buf=numpy.zeros(nbuf,dtype=numpy.uint8) # i.e., an array of bytes f=open('dump.data','w')