机器学习函数

1 tf.shape()
import tensorflow as tf
import numpy as np
a_array = np.array([[1,2,3], [4,5,6]])
b_list = [[1,2,3],[3,4,5]]
c_tensor = tf.constant([[1,2,3], [4,5,6]])

with tf.Session() as sess:
	print(sess.run(tf.shape(a_array)))
	print(sess.run(tf.shape(b_list)))
	print(sess.run(tf.shape(c_tensor)))

>>> [2,3], [2,3],  [2,3]
2 x.get_shape().as_list()

x.get_shape(), 只有tensor才可以使用这种方法,返回的是一个元组

import tensorflow as tf
import numpy as np

a_array = np.array([[1,2,3], [4,5,6]])
b_list = [[1,2,3],[3,4,5]]
c_tensor = tf.constant([[1,2,3], [4,5,6]])
print(c_tensor.get_shape())
print(c_tensor.get_shape().as_list())
with tf.Session() as sess:
	print(sess.run(tf.shape(a_array)))
	print(sess.run(tf.shape(b_list)))
	print(sess.run(tf.shape(c_tensor)))

>>> (2,3), [2,3], [2,3], [2,3], [2,3]
3 tf.split()

tf.split(dimension, num_split, input):dimension的意思就是输入张量的哪一个维度,如果是0就表示对第0维度进行切割。num_split就是切割的数量,如果是2就表示输入张量被切成2份,每一份是一个列表。

import tensorflow as tf
import numpy as np

A = [[1,2,3], [4,5,6]]
x = tf.split(1,3,A)

with tf.Session() as sess:
	c = sess.run(x)
	for ele in c:
		print(ele)

>>>[[1],
  	[4]]
   [[2],
  	[5]]
   [[3],
  	[6]]

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值