张量的标量乘法
Scalar multiplication of tensors
在 Python 的 TensorFlow Core 中有一个名为 tf.math.scalar_mul
的操作。
我想在 TensorFlow.js 中缩放张量。通过尝试 a * 0.1
我收到一条错误消息(至少来自 Typescript):The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362)
.
缩放张量是否适用于不将它们设为数组、按元素缩放然后转换回张量的情况?
我在 API documentation 中找到了答案。要将张量 a
乘以 5,只需 a.mul(tf.scalar(5))
.
虽然可以使用tf.scalar
,但也可以像下面这样直接使用tensor.mul(number)
tf.tensor([1, 2, 3, 4]).mul(5).print(); // [5, 10, 15, 20]
在 Python 的 TensorFlow Core 中有一个名为 tf.math.scalar_mul
的操作。
我想在 TensorFlow.js 中缩放张量。通过尝试 a * 0.1
我收到一条错误消息(至少来自 Typescript):The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.ts(2362)
.
缩放张量是否适用于不将它们设为数组、按元素缩放然后转换回张量的情况?
我在 API documentation 中找到了答案。要将张量 a
乘以 5,只需 a.mul(tf.scalar(5))
.
虽然可以使用tf.scalar
,但也可以像下面这样直接使用tensor.mul(number)
tf.tensor([1, 2, 3, 4]).mul(5).print(); // [5, 10, 15, 20]