python - “避免覆盖输入张量”是什么意思?
问题描述
我一直在研究 Francois Chollet 的书 Deep Learning with python,并且有一个操作,他总是在他的一些函数中不断重复。
x = x.copy()
书中说这样做是为了“避免覆盖输入张量”。
我将在这里发布一个示例代码,他使用此语句。
def naive_add(x, y):
assert len(x.shape) == 2
assert x.shape == y.shape
x = x.copy() #Avoid overwriting the input tensor.
for i in range(x.shape[0]):
for j in range(x.shape[1]):
x[i, j] += y[i, j]
return x
这是两个二维张量的元素加法的简单代码。看懂了代码,但是想了解一下x=x.copy
这个函数中这行的意义。
解决方案
推荐阅读
- xcode - Xcode - 上传图像并设置为背景
- mysql - MySql - 如何在不明确指定所有非键列的情况下插入和重复键更新
- javascript - 如何在 JSP 标记属性中调用 JavaScript 函数
- javascript - echarts(折线图)无数据时如何连接
- powershell - 如何使用 PowerShell 在下面的脚本中选择服务器名称?
- javascript - 在表格中分离 D3 饼图
- javascript - 悬停在链接上时动画自定义光标
- javascript - 如何从父 div 中弹出子 div 的内容?
- javascript - 换行符在 contenteditable div 中计为 2 个字符
- phpmailer - 尝试发送邮件时,PHP 邮件程序在 php 7 中引发错误