squeeze

squeeze(x)

Try it yourself:


squeeze(): Removing Singleton Dimensions

squeeze() removes dimensions of length one from an array or matrix. It makes data easier to work with after slicing or importing a shape such as 1×n×1.

Shape changes

squeeze changes dimensions but not the stored values. Inspect before and after with size(). Use reshape() when you need a specific target shape rather than automatic removal.

Be careful when a singleton dimension carries meaning, such as a batch or channel axis. Use subset() for deliberate selection and transpose() when orientation matters.

Try Squeeze in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions