what is the time complexity of function 'reshape'

18 ビュー (過去 30 日間)
warnerchang
warnerchang 2022 年 4 月 10 日
コメント済み: warnerchang 2022 年 4 月 11 日
anyone knows what is the time complexity of function 'reshape'?

採用された回答

Jan
Jan 2022 年 4 月 10 日
In reshape the actual data are not touched, but only the vector of dimension. This vector is changed, so Matlab has to allocate a new vector. The checks, if the number of elements are compatible is most likely mire expensive then allocating the vector of the new dimensions. In addition you will most likely use less than 20 dimensions. Therefore I conclude, that reshape runs in almost fixed time.
  1 件のコメント
warnerchang
warnerchang 2022 年 4 月 11 日
thank you for your reply!

サインインしてコメントする。

その他の回答 (1 件)

John D'Errico
John D'Errico 2022 年 4 月 10 日
編集済み: John D'Errico 2022 年 4 月 10 日
Essentially, almost zero time (a small constant amount that is almost negligable.) All reshape itself does is modify a flag attached to the array, that tells MATLAB what shape the array is. NO elements are moved around by a reshape. Of course, if you will then be doing something with that reshaped array, perhaps creating a new variable, that is different. But there, the time will be spent allocating a new variable, and copying elements, etc. But the reshape itself is virtually instantaneous.
  1 件のコメント
warnerchang
warnerchang 2022 年 4 月 11 日
thank you for your reply!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by