Skip to content

Commit

Permalink
Fixed byte size computation for numpy array
Browse files Browse the repository at this point in the history
* `len(A)` returns the number of rows (which is 1024 in this case) while the total number of elements is to be retrieved with `A.size`
* the exact byte size of each element can be obtained with `A.itemsize` regardless of the actual `dtype` used for the array

with these changes the original size is correctly computed as 8388608 bytes which is exactly 8Mb
  • Loading branch information
splendido committed Mar 6, 2015
1 parent efd8903 commit c6a6a93
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions examples/serialization/serialsocket.py
Expand Up @@ -57,7 +57,7 @@ def main():
rep.bind('inproc://a')
req.connect('inproc://a')
A = numpy.ones((1024,1024))
print ("Array is %i bytes" % (len(A) * 8))
print ("Array is %i bytes" % (A.size * A.itemsize))

# send/recv with pickle+zip
req.send_zipped_pickle(A)
Expand All @@ -71,4 +71,4 @@ def main():
print ("Okay" if (C==B).all() else "Failed")

if __name__ == '__main__':
main()
main()

0 comments on commit c6a6a93

Please sign in to comment.