如何在每個元素中找到最大值,以便得到 2、4、6、8?
import tensorflow as tf
a = tf.constant([
[[1, 2]], [[3, 4]],
[[5, 6]], [[7, 8]]])
我嘗試了以下代碼:
tf.reduce_max(a, keepdims=True)
但這只是給了我 8 作為輸出而忽略了其余部分。
uj5u.com熱心網友回復:
您必須axis像這樣將引數更改為 -1:
import tensorflow as tf
a = tf.constant([
[[1, 2]], [[3, 4]],
[[5, 6]], [[7, 8]]])
print(tf.reduce_max(a, axis=-1, keepdims=False))
'''
tf.Tensor(
[[2]
[4]
[6]
[8]], shape=(4, 1), dtype=int32)
'''
因為您有一個 3D 張量并且想要訪問最后一個維度。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/323901.html
標籤:张量流
上一篇:Nginx在容器的AzureWeb應用程式中的DockeredDjango應用程式中找不到靜態檔案
下一篇:只有整數、切片(`:`)、省略號(`...`)、tf.newaxis(`None`)和標量tf.int32/tf.int64張量是有效索引,得到array([219,928,
