What is the difference between [None, ...] and unsqueeze?

What is the difference between [None, ...] and .unsqueeze(0) when adding a new dimension to data?

In my test, both methods share the original storage and .unsqueeze(0) is slightly faster. Is [None, ...] just a wrapper of .unsqueeze()?

Thanks.

2 Likes

Hi,

[None, ...] is numpy notation for .unsqueeze(0). The two are equivalent. The version with advanced indexing might be a bit slower because it has more checking to do to find out exactly what you want to do.

5 Likes