[英]What is the time complexity for tf.transpose in tensorflow?
For example, assume we have an tensor a
with input shape (10,32,32,3) Which means 10 32*32 RGB pictures with NHWC format例如,假设我们有一个输入形状为 (10,32,32,3) 的张量a
,这意味着 10 张 32*32 的 NHWC 格式的 RGB 图片
and I want to use tf.transpose(b, perm=[0, 3, 1, 2])
to convert it into NCHW format我想使用tf.transpose(b, perm=[0, 3, 1, 2])
将其转换为 NCHW 格式
What is the time complexity of this operation?这个操作的时间复杂度是多少?
---------FORWARD--------- - - - - -向前 - - - - -
I found that the time complexity of numpy transpose function is O(1), according to the following link我发现numpy转置函数的时间复杂度是O(1),根据下面的链接
https://www.thetopsites.net/article/58279082.shtml https://www.thetopsites.net/article/58279082.shtml
Is that the same in tf?这在tf中是一样的吗?
Matrix transposition for a 2D matrix is O(dim1*dim2)
.二维矩阵的矩阵转置是O(dim1*dim2)
。
For a 3D matrix it would be O(dim1*dim2*dim3)
and so on.对于 3D 矩阵,它将是O(dim1*dim2*dim3)
等等。
According to the 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
That means that the complexity depends on the dimensions of your tensor.这意味着复杂性取决于张量的维度。 Assuming that you have k
dimensions of n
-size each, it would mean O(n^k)
.假设你有k
个n
尺寸的维度,这意味着O(n^k)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.