【发布时间】:2021-01-06 17:16:57
【问题描述】:
def kiem_tra_so_hoan_chinh(so):
if so <= 1:
return False
else:
tong = 0
for i in range(1, so):
if so % i == 0:
tong += i
if tong == so:
return True
else:
return False
np.random.seed(5)
arr1 = np.random.randint(low = 1, high = 101, size = 16)
arr1=arr1.reshape(4,4)
arr1
如果 arr1 包含完美数字,我如何将函数用于数组并打印出 arr1 行
如果我使用kiem_tra_so_hoan_chinh(arr1),它会显示错误:
"ValueError: 多元素数组的真值不明确。使用a.any()或a.all()"
【问题讨论】:
标签: python arrays function numpy