TensorFlow-tf.linspace

31 篇文章 0 订阅
4 篇文章 0 订阅

tf.linspace

沿给定轴在间隔内生成均匀间隔的值。

tf.linspace(start, stop, num, name=None, axis=0)
参数
start张量。必须为以下类型:bfloat16,float32,float64。N-D张量。范围中的第一项。
stop张量。必须和start有相同的类型和形状。N-D张量。范围中的最后一项。
num张量。必须为以下类型:int32,int64。0-D张量。生成数值的数量。
name操作的名称(可选)。
axis执行操作的Axis(仅在提供N-D张量时使用)。
Returns张量。和start有相同的类型。

从起始点开始,沿着给定的轴生成一个num均匀间隔值序列。

如果num > 1,序列中的值加(stop - start) / (num - 1),最后一个值正好是stop。

如果num <= 0,则引发ValueError。

实例

(python3.7) E:\PYTHON>python
Python 3.7.16 (default, Jan 17 2023, 16:06:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
>>> tf.linspace(10.0, 12.0, 3, name="linspace")
2023-03-28 10:38:30.881152: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([10., 11., 12.], dtype=float32)>
>>>

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是生成值的地方(对应于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)>

内容参考自:https://www.tensorflow.org/api_docs/python/tf/linspace

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天寒心亦热

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值