Numpy recarray.byteswap () function | python

Record arrays allow you to access fields as elements of an array using arr.a and arr.b numpy.recarray.byteswap () in places bytes of array elements.

Syntax: numpy.recarray.byteswap(inplace=False)

Parameters:
inplace: [bool, optional] If True, swap bytes in-place, default is False.

Return : [ndarray] byteswapped array. If inplace is True, this is a view to self.

Code :

# Python program explaining
# numpy.recarray.byteswap () method

 
# importing numy as a geek

import numpy as geek

  
# create an input array with two different fields

in_arr = geek.array ([ ( 5.0 , 2 ), ( 3.0 , - 4 ), ( 6.0 , 9 )],

dtype = [( `a` , float ), ( `b` , int )])

print ( "Input array:" , in_arr )

 
# convert it to an array of posts,
# using arr.view (np.recarray)

rec_arr = in_arr.view (geek.recarray) < / code>

 

 
# using recarray.byteswap methods to write an array

out_arr = rec_arr.byteswap ()

print ( "Output swapped record array:" , out_arr) 

Output :

 Input array: [(5.0, 2) (3.0, -4) (6.0, 9)] Output swapped record array: [(2.561e-320, 144115188075855872) (1.0435e-320, -216172782113783809) (3.067e-320, 648518346341351424)]