Thursday, September 4, 2025
HomeLanguagesNumpy ndarray.getfield() function | Python

Numpy ndarray.getfield() function | Python

numpy.ndarray.getfield() function return a field of the given array as a certain type.

Syntax : numpy.ndarray.getfield(dtype, offset=0)

Parameters :
dtype : [str or dtype] The dtype size of the view can not be larger than that of the array itself.
offset : [int] Number of bytes to skip before beginning the element view.

Return : Returns a field of the given array as a certain type.

Code #1 :




# Python program explaining
# numpy.ndarray.getfield() function
  
# importing numpy as geek 
import numpy as geek 
            
x = geek.diag([1.+1.j]*2)
            
gfg = x.getfield(geek.float64)
      
print(gfg)


Output :

[[ 1.  0.]
 [ 0.  1.]]

 
Code #2 :




# Python program explaining
# numpy.ndarray.getfield() function
  
# importing numpy as geek 
import numpy as geek 
            
x = geek.diag([2.+2.j]*2)
            
gfg = x.getfield(geek.float64, offset = 8)
      
print(gfg)


Output :

[[ 2.  0.]
 [ 0.  2.]]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6628 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS