當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python numpy.may_share_memory()用法及代碼示例

numpy.may_share_memory()函數確定兩個陣列是否可以共享內存。

用法: numpy.may_share_memory(arr1, arr2, max_work = None)
參數:
arr1, arr2: [ndarray] Input arrays.
max_work: [int, optional] Effort to spend on solving the overlap problem.
返回: [bool] Checking if two arrays might share memory. A return of True does not necessarily mean that the two arrays share any element. It just means that they might.

代碼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

相關用法


注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.may_share_memory() function – Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。