def serialize_numpy(m, t):
<EOL>header = array('<STR_LIT:i>', [len(m.shape)] + list(m.shape))<EOL>body = array(t, m.flatten().tolist())<EOL>if sys.byteorder != '<STR_LIT>':<EOL><INDENT>header.byteswap()<EOL>body.byteswap()<EOL><DEDENT>return bytearray(header.tostring() + body.tostring())<EOL>
serialize_numpy(m, type) converts the numpy array m into a byte stream that can be read by the
nben.util.Py4j Java class. The function assumes that the type of the array needn't be encoded
in the bytearray itself. The bytearray will begin with an integer, the number of dimensions,
followed by that number of integers (the dimension sizes themselves) then the bytes of the
array, flattened.
The argument type gives the type of the array to be transferred and must be 'i' for integer or
'd' for double (or any other string accepted by array.array()).