import tensorflow as tf
import numpy as np
x = np.ones((2,3,3,1))
z = tf.argmax(x,axis = 3)
print(z.get_shape())
with tf.Session() as sess:
print(sess.run(z))
(2, 3, 3)
[[[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]]]
z = tf.argmax(x,axis = 2)和z = tf.argmax(x,axis = 1)
(2, 3, 1)
[[[0]
[0]
[0]]
[[0]
[0]
[0]]]
z = tf.argmax(x,axis = 0)
(3, 3, 1)
[[[0]
[0]
[0]]
[[0]
[0]
[0]]
[[0]
[0]
[0]]]
import tensorflow as tf
import numpy as np
a = np.arange(8.0).reshape(2,2,2)
b = tf.reduce_mean(a,axis=[1,2],keepdims=True)
print(b.get_shape())
with tf.Session() as sess:
b=sess.run(b)
print(a)
print(b)
(2, 1, 1)
[[[0. 1.]
[2. 3.]]
[[4. 5.]
[6. 7.]]]
[[[1.5]]
[[5.5]]]
axis=0垂直屏幕。axis=1纵向,axis=2横向(计算机的传统)。axis=[1,2]就是垂直屏幕的平面各自去平均值了,可以分解为axis=1取平均,然后axis=2取平均。
import tensorflow as tf
import numpy as np
a = np.arange(8.0).reshape(2,2,2)
b = tf.reduce_mean(a,axis= 1,keepdims=True)
print(b.get_shape())
with tf.Session() as sess:
b=sess.run(b)
print(a)
print(b)
(2, 1, 2)
[[[0. 1.]
[2. 3.]]
[[4. 5.]
[6. 7.]]]
[[[1. 2.]]
[[5. 6.]]]
import tensorflow as tf
import numpy as np
a = np.arange(24.0).reshape(2,2,2,3)
b = tf.reduce_mean(a,axis=[1,2],keepdims=True)
print(b.get_shape())
with tf.Session() as sess:
b=sess.run(b)
#print(a)
print(b)
(2, 1, 1, 3)
[[[[ 4.5 5.5 6.5]]]
[[[16.5 17.5 18.5]]]]
import tensorflow as tf
import numpy as np
a = np.arange(24.0).reshape(2,2,2,3)
b = tf.reduce_mean(a,axis=[0],keepdims=True)
print(b.get_shape())
with tf.Session() as sess:
b=sess.run(b)
print(b)
[[[[ 6. 7. 8.]
[ 9. 10. 11.]]
[[12. 13. 14.]
[15. 16. 17.]]]]
import tensorflow as tf
import numpy as np
a = np.arange(24.0).reshape(2,2,2,3)
b = tf.reduce_mean(a,axis=[0,3],keepdims=True)
print(b.get_shape())
with tf.Session() as sess:
b=sess.run(b)
print(b)
[[[[ 7.]
[10.]]
[[13.]
[16.]]]]