codecamp

使用Dimension类

tf.Dimension

Dimension 类

定义在:tensorflow/python/framework/tensor_shape.py

请参阅指南:构建图表>定义新操作

表示 TensorShape 中一个维度的值.

属性

value:此维度的值,如果未知,则为“None”.

方法

__init__

__init__(value)

用给定的值创建一个新的维度.

__add__

__add__(other)

返回自身和其他维度的总和.
维度的总和计算如下:
维度 (m) + 维度 (n) = = 维度 (m + n) 维度 (m) + 维度 (无) == 维度(无) 维度 (无) + 维度 (n) = = 维度 (无) 维度 (无) + 维度 (无) == 维度 (无)

(Dimension(m) + Dimension(n) == Dimension(m + n) Dimension(m) + Dimension(None) == Dimension(None) Dimension(None) + Dimension(n) == Dimension(None) Dimension(None) + Dimension(None) == Dimension(None)

)

ARGS:

  • other:另一个维度.

返回:

其值是自身和其他维度的总和.

__div__

__div__(other)

不推荐使用:您可以使用 __floordiv__ 通过 x // y 代替它.

此函数仅用于向后兼容性目的;新的代码应该使用 __floordiv__ 通过语法使用 x // y.使用 x//y 可以清楚地传达结果,并且与 Python 3 的转发兼容.

ARGS:

  • other:另一个维度.

返回:

其值是自身和其他维度的整数商.

__eq__

__eq__(other)

如果其他具有与此维度相同的已知值, 则返回 true.

__floordiv__

__floordiv__(other)

返回自身维度的商以及其他维度的四舍五入.
维度划分如下:

Dimension(m) // Dimension(n) == Dimension(m // n) Dimension(m) // Dimension(None) == Dimension(None) Dimension(None) // Dimension(n) == Dimension(None) Dimension(None) // Dimension(None) == Dimension(None)

ARGS:

  • other:另一个维度.

返回:

其值是自身维度和其他维度的整数商.

__ge__

__ge__(other)

如果已知自身维度大于或等于其他维度值,则返回 True.
维度的比较如下:

Dimension(m) >= Dimension(n) == m >= n Dimension(m) >= Dimension(None) == None Dimension(None) >= Dimension(n) == None Dimension(None) >= Dimension(None) == None

ARGS:

  • other:另一个维度.

返回:

如果两者都是已知则返回 self.value >= other.value 的值,否则返回 None.

__gt__

__gt__(other)

如果已知自身维度大于其他维度值,则返回 True.

维度的比较如下:

Dimension(m) > Dimension(n) == m > n Dimension(m) > Dimension(None) == None Dimension(None) > Dimension(n) == None Dimension(None) > Dimension(None) == None

ARGS:

  • other:另一个维度.

返回:

如果两者都是已知则返回 self.value > other.value 的值,否则返回 None.

__index__

__index__ ()

__int__

__int__ ()

__le__

__le__ (other)

如果已知自身维度小于或等于其他维度值,则返回 True.

维度比较如下:

Dimension(m) <= Dimension(n) == m <= n Dimension(m) <= Dimension(None) == None Dimension(None) <= Dimension(n) == None Dimension(None) <= Dimension(None) == None

ARGS:

  • other:另一个维度.

返回:

如果两者都是已知则返回 self.value <= other.value 的值,否则返回 None.

__long__

__long__ ()

__lt__

__lt__ (other)

如果已知自身维度小于其他维度值,则返回 True.

维度比较如下:

Dimension(m) < Dimension(n) == m < n Dimension(m) < Dimension(None) == None Dimension(None) < Dimension(n) == None Dimension(None) < Dimension(None) == None

ARGS:

  • other:另一个维度.

返回:

如果两者都是已知则返回 self.value < other.value 的值,否则返回 None.

__mod__

__mod__ (other)

返回自身维度与其他维度的模.

维度模量计算如下:

Dimension(m) % Dimension(n) == Dimension(m % n) Dimension(m) % Dimension(None) == Dimension(None) Dimension(None) % Dimension(n) == Dimension(None) Dimension(None) % Dimension(None) == Dimension(None)

ARGS:

  • other:另一个维度.

返回:

值为 self 与 other 模的维度.

__mul__

__mul__ (other)

返回 self 和 other 的乘积.

维度总和如下:

Dimension(m)    * Dimension(n)    == Dimension(m * n)
Dimension(m)    * Dimension(None) == Dimension(None)
Dimension(None) * Dimension(n)    == Dimension(None)
Dimension(None) * Dimension(None) == Dimension(None)

ARGS:

  • other:另一个维度.

返回:

一个维度,它的值是 self 和 other 的乘积.

__ne__

__ne__ (other)

如果 other 具有与 self 不同的已知值,则返回 true.

__sub__

__sub__ (other)

返回从 self 中减去的 other.

维度减去如下:

Dimension(m) - Dimension(n) == Dimension(m - n) Dimension(m) - Dimension(None) == Dimension(None) Dimension(None) - Dimension(n) == Dimension(None) Dimension(None) - Dimension(None) == Dimension(None)

ARGS:

  • other:另一个维度.

返回:

一个维度,它的值是 self 和 other 总和的减法.

assert_is_compatible_with

assert_is_compatible_with (other)

如果 other 与此维度不兼容,则引发异常.

ARGS:

  • other:另一个维度.

注意:

  • ValueError:如果 self 和 other 不兼容(请参阅 is_compatible_with).

is_compatible_with

is_compatible_with (other)

如果 other 与此维度兼容,则返回 true .

两个已知的维度如果具有相同的值则是兼容的.未知的维度与所有其他维度兼容.

ARGS:

  • other:另一个维度.

返回:

如果这个维度与 other 是兼容的,则为true .

merge_with

merge_with (other)

返回一个 self 和 other 合并了信息的维度.
维度按如下方式组合:

Dimension(n)   .merge_with(Dimension(n))    == Dimension(n)
Dimension(n)   .merge_with(Dimension(None)) == Dimension(n)
Dimension(None).merge_with(Dimension(n))    == Dimension(n)
Dimension(None).merge_with(Dimension(None)) == Dimension(None)
Dimension(n)   .merge_with(Dimension(m)) raises ValueError for n != m

ARGS:

  • other:另一个维度.

返回:

返回一个维度含有 self 和 other 的组合信息.

注意:

  • ValueError:如果 self 和 other 不兼容(请参阅 is_compatible_with).


TensorFlow除法运算
TensorFlow张量的元素类型
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }