在給定軸的間隔中生成 evenly-spaced 值。
用法
tf.linspace(
start, stop, num, name=None, axis=0
)
參數
-
start
一個Tensor
。必須是以下類型之一:bfloat16
,float32
,float64
。 N-D 張量。範圍內的第一個條目。 -
stop
一個Tensor
。必須具有與start
相同的類型和形狀。 N-D 張量。範圍內的最後一個條目。 -
num
一個Tensor
。必須是以下類型之一:int32
,int64
。 0-D 張量。要生成的值的數量。 -
name
操作的名稱(可選)。 -
axis
執行操作的軸(僅在提供N-D 張量時使用)。
返回
-
一個
Tensor
。具有與start
相同的類型。
沿著給定的 axis
從 start
開始生成一係列 num
evenly-spaced 值。如果 num > 1
,則序列中的值增加 (stop - start) / (num - 1)
,因此最後一個值正好是 stop
。如果提出num <= 0
, ValueError
。
匹配 np.linspace 的行為,但 num == 0
除外。
例如:
tf.linspace(10.0, 12.0, 3, name="linspace") => [ 10.0 11.0 12.0]
Start
和 stop
可以是任意大小的張量:
tf.linspace([0., 5.], [10., 40.], 5, axis=0)
<tf.Tensor:shape=(5, 2), dtype=float32, numpy=
array([[ 0. , 5. ],
[ 2.5 , 13.75],
[ 5. , 22.5 ],
[ 7.5 , 31.25],
[10. , 40. ]], dtype=float32)>
Axis
是生成值的位置(返回的張量中對應於軸的維度將等於 num
)
tf.linspace([0., 5.], [10., 40.], 5, axis=-1)
<tf.Tensor:shape=(2, 5), dtype=float32, numpy=
array([[ 0. , 2.5 , 5. , 7.5 , 10. ],
[ 5. , 13.75, 22.5 , 31.25, 40. ]], dtype=float32)>
相關用法
- Python tf.linalg.LinearOperatorFullMatrix.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solve用法及代碼示例
- Python tf.linalg.LinearOperatorIdentity.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorPermutation.solve用法及代碼示例
- Python tf.linalg.band_part用法及代碼示例
- Python tf.linalg.LinearOperatorKronecker.diag_part用法及代碼示例
- Python tf.linalg.lu_matrix_inverse用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorBlockLowerTriangular.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorLowerTriangular.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.solve用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant3D.diag_part用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.assert_non_singular用法及代碼示例
- Python tf.linalg.LinearOperatorPermutation.diag_part用法及代碼示例
- Python tf.linalg.LinearOperatorToeplitz用法及代碼示例
- Python tf.linalg.LinearOperatorCirculant2D.matvec用法及代碼示例
- Python tf.linalg.LinearOperatorTridiag.solvevec用法及代碼示例
- Python tf.linalg.LinearOperatorTridiag.solve用法及代碼示例
- Python tf.linalg.LinearOperatorZeros.matmul用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.linspace。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。