📜  numpy.may_share_memory()函数– Python

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

numpy.may_share_memory()函数– Python

numpy.may_share_memory()函数确定两个数组是否可以共享内存。

代码#1:

# Python program explaining
# numpy.may_share_memory() function
             
# importing numpy as geek 
import numpy as geek 
    
arr1 = geek.array([1, 2, 3, 4])
arr2 = geek.array([5, 6, 7])
   
gfg = geek.may_share_memory(arr1, arr2)
       
print (gfg)

输出 :

False


代码#2:

# Python program explaining
# numpy.may_share_memory() function
            
# importing numpy as geek 
import numpy as geek 
   
arr1 = geek.zeros([3, 4])
arr2 = arr1[::1]
  
gfg = geek.may_share_memory(arr1, arr2)
      
print (gfg)

输出 :

True