resize

resize(x, size)

resize(x, size, defaultValue)

Try it yourself:


resize(): Changing Collection Size

resize() changes a collection or matrix to requested dimensions. Unlike reshape(), it may add new positions or discard existing data when the total size changes.

Data-loss caution

Reducing a dimension can remove entries, so inspect the original with size() and keep a copy with clone() when needed. Enlarging an array requires a defined fill behavior; make default values explicit.

Use zeros() or ones() when creating a new fixed-size matrix is clearer. resize is best for controlled shape adaptation, not as a substitute for validating input dimensions.

All functions