Open In App

Numpy ndarray.tobytes() function | Python

Last Updated : 22 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
numpy.ndarray.tobytes() function construct Python bytes containing the raw data bytes in the array.
Syntax : numpy.ndarray.tobytes(order='C') Parameters : order : [{‘C’, ‘F’, None}, optional] Order of the data for multidimensional arrays: C, Fortran, or the same as for the original array. Return : Python bytes exhibiting a copy of arr’s raw data.
Code #1 : Python3
# Python program explaining
# numpy.ndarray.tobytes() function

# importing numpy as geek 
import numpy as geek

arr = geek.array([[0, 1], [2, 3]], dtype ='<u2')

gfg = arr.tobytes()

print (gfg)
Output :
b'\x00\x00\x01\x00\x02\x00\x03\x00'
  Code #2 : Python3
# Python program explaining
# numpy.ndarray.tobytes() function

# importing numpy as geek 
import numpy as geek

arr = geek.array([[0, 1], [2, 3]], dtype ='<u2')

gfg = arr.tobytes('F')

print (gfg)
Output :
b'\x00\x00\x02\x00\x01\x00\x03\x00'

Similar Reads

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy