TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
reduce_any()用於計算跨張量維度的元素的“logical or”。
用法:tensorflow.math.reduce_any( input_tensor, axis, keepdims, name)
參數:
- input_tensor:減少布爾張量。
- axis(optional):它表示要縮小的尺寸。其值應在[-rank(input_tensor),rank(input_tensor))範圍內。如果對此沒有給出值,則所有尺寸都會減小。
- keepdims(optional):默認值為False。如果將其設置為True,它將保留長度為1的縮小尺寸。
- name(optional):它定義了操作的名稱。
返回值:它返回一個張量。
範例1:
Python3
# importing the library
import tensorflow as tf
# Initializing the input tensor
a = tf.constant([True, False, False, True], dtype = tf.bool)
# Printing the input tensor
print('Input:', a)
# Calculating result
res = tf.math.reduce_any(a)
# Printing the result
print('Result:', res)
輸出:
Input: tf.Tensor([ True False False True], shape=(4, ), dtype=bool) Result: tf.Tensor(True, shape=(), dtype=bool)
範例2:
Python3
# importing the library
import tensorflow as tf
# Initializing the input tensor
a = tf.constant([[True, False], [False, True]], dtype = tf.bool)
# Printing the input tensor
print('Input:', a)
# Calculating result
res = tf.math.reduce_any(a, axis = 1, keepdims = True)
# Printing the result
print('Result:', res)
輸出:
Input: tf.Tensor( [[ True False] [False True]], shape=(2, 2), dtype=bool) Result: tf.Tensor( [[ True] [ True]], shape=(2, 1), dtype=bool)
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.reduce_any()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。