HomeLanguagesNumpy ndarray.setfield() function | Python

Numpy ndarray.setfield() function | Python

numpy.ndarray.setfield() function Put a value into a specified place in a field defined by a data-type. Place val into a’s field defined by dtype and beginning offset bytes into the field.

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

Parameters :
val : [object] Value to be placed in field.
dtype : [dtype object] Data-type of the field in which to place val.
offset : [int, optional] The number of bytes into the field at which to place val.

Return : None.

Code #1 :




# Python program explaining
# numpy.ndarray.setfield() function
  
# importing numpy as geek 
import numpy as geek 
            
arr = geek.eye(4)
            
arr.setfield(4, geek.int32)
gfg = arr.getfield(geek.int32)
      
print(gfg)


Output :

[[4 4 4 4]
 [4 4 4 4]
 [4 4 4 4]
 [4 4 4 4]]

 
Code #2 :




# Python program explaining
# numpy.ndarray.setfield() function
  
# importing numpy as geek 
import numpy as geek 
            
arr = geek.eye(2)
            
arr.setfield(2, geek.int32)
gfg = arr.getfield(geek.int32)
      
print(gfg)


Output :

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

Most Popular

Dominic
32688 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7057 POSTS0 COMMENTS
Nicole Veronica
12198 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12293 POSTS0 COMMENTS
Shaida Kate Naidoo
7182 POSTS0 COMMENTS
Ted Musemwa
7447 POSTS0 COMMENTS
Thapelo Manthata
7160 POSTS0 COMMENTS
Umr Jansen
7150 POSTS0 COMMENTS