import numpy as np
import tensorflow as tf
a = np.array([
[1,2,3],
[4,5,6],
[7,8,9]
])
#矩阵 a[:] 于a[:,]区别
print(a[:1]) #按照行输出
print(a[:,1]) #输出第二列
print(a[:2])
'''
For example:
x = tf.constant([1, 4])
y = tf.constant([2, 5])
z = tf.constant([3, 6])
tf.stack([x, y, z]) # [[1, 4], [2, 5], [3, 6]] (Pack along first dim.)
tf.stack([x, y, z], axis=1) # [[1, 2, 3], [4, 5, 6]]
stack作用:
对列表进行打包划分
参数:
1 :是列表,若是矩阵需要转化为列表
2 , 默认axis=0, 代表行画分, axis=1,代表列画分
'''
st1 = tf.stack(a[:2].tolist(),axis=1)
st = tf.stack(a.tolist(),axis = 1)
with tf.Session() as sess:
print(sess.run(st))
'''
[[1 4 7]
[2 5 8]
[3 6 9]]
'''tensorflow中的stack与numpy切片
最新推荐文章于 2024-05-05 20:19:43 发布
本文通过实例演示了如何使用NumPy与TensorFlow进行数组操作,包括选取、切片和堆叠等基本操作。同时介绍了tf.stack函数的用法及其参数axis的意义,帮助读者更好地理解这些常用操作。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
TensorFlow-v2.15
TensorFlow
TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型
2376

被折叠的 条评论
为什么被折叠?



