【问题标题】:What is the time complexity for tf.transpose in tensorflow?张量流中 tf.transpose 的时间复杂度是多少?
【发布时间】:2020-09-12 18:37:28
【问题描述】:

例如,假设我们有一个张量 a 输入形状 (10,32,32,3) 即10张NHWC格式的32*32 RGB图片

我想用tf.transpose(b, perm=[0, 3, 1, 2])把它转换成NCHW格式

这个操作的时间复杂度是多少?

---------向前---------

我发现numpy转置函数的时间复杂度是O(1),根据以下链接

https://www.thetopsites.net/article/58279082.shtml

在 tf 中也一样吗?

【问题讨论】:

    标签: python tensorflow time-complexity


    【解决方案1】:

    二维矩阵的矩阵转置是O(dim1*dim2)

    对于 3D 矩阵,它将是 O(dim1*dim2*dim3) 等等。

    【讨论】:

      【解决方案2】:

      根据source

      @compatibility(numpy)
        In `numpy` transposes are memory-efficient constant time operations as they
        simply return a new view of the same data with adjusted `strides`.
        TensorFlow does not support strides, so `transpose` returns a new tensor with
        the items permuted.
      @end_compatibility
      

      这意味着复杂性取决于张量的维度。假设您的k 尺寸为n-size,则意味着O(n^k)

      【讨论】:

        猜你喜欢
        • 2018-11-24
        • 2014-05-27
        • 1970-01-01
        • 1970-01-01
        • 2012-02-13
        • 2016-08-21
        • 2017-03-19
        • 2013-05-21
        相关资源
        最近更新 更多