📜  Numpy ndarray.getfield()函数| Python

📅  最后修改于: 2022-05-13 01:55:51.081000             🧑  作者: Mango

Numpy ndarray.getfield()函数| Python

numpy.ndarray.getfield()函数将给定数组的字段作为某种类型返回。

代码#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)

输出 :

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


代码#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)

输出 :

[[ 2.  0.]
 [ 0.  2.]]