码迷,mamicode.com
首页 > 其他好文 > 详细

tf.constant

时间:2018-05-23 20:37:07      阅读:580      评论:0      收藏:0      [点我收藏+]

标签:cal   type   with   list   constant   value   创建   17.   color   

创建一个常数张量,传入list或者数值来填充

   # Constant 1-D Tensor populated with value list.
   tensor = tf.constant([1, 2, 3, 4, 5, 6, 7]) => [1 2 3 4 5 6 7]

   # Constant 2-D tensor populated with scalar value -1.
   tensor = tf.constant(-1.0, shape=[2, 3]) => [[-1. -1. -1.]

  # 2-D tensor `a`
  a = tf.constant([1, 2, 3, 4, 5, 6], shape=[2, 3]) => [[1. 2. 3.]
                                                        [4. 5. 6.]]
  # 2-D tensor `b`
  b = tf.constant([7, 8, 9, 10, 11, 12], shape=[3, 2]) => [[7. 8.]
                                                           [9. 10.]
                                                           [11. 12.]]
  # 3-D tensor `a`
  a = tf.constant(np.arange(1, 13, dtype=np.int32),
                  shape=[2, 2, 3])                  => [[[ 1.  2.  3.]
                                                         [ 4.  5.  6.]],
                                                        [[ 7.  8.  9.]
                                                         [10. 11. 12.]]]

  # 3-D tensor `b`
  b = tf.constant(np.arange(13, 25, dtype=np.int32),
                  shape=[2, 3, 2])                   => [[[13. 14.]
                                                          [15. 16.]
                                                          [17. 18.]],
                                                         [[19. 20.]
                                                          [21. 22.]
                                                          [23. 24.]]]

 

tf.constant

标签:cal   type   with   list   constant   value   创建   17.   color   

原文地址:https://www.cnblogs.com/Ph-one/p/9078804.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!