promote_shape(s1, s2)

Check two array shapes for compatibility, allowing trailing singleton dimensions, and return whichever shape has more dimensions.


julia> promote_shape((2,), (3, 1))
(3, 1)

julia> promote_shape((4, 5), (4, 1, 3))
(4, 5, 3)

In the first example, the shape (2,) and (3, 1) are compared. Since both shapes have the same number of dimensions, the function returns the shape (3, 1).

In the second example, the shape (4, 5) and (4, 1, 3) are compared. The shape (4, 1, 3) has more dimensions, so it is returned as the promoted shape.

The promote_shape function is commonly used when working with arrays of different shapes and dimensions. It ensures compatibility between the shapes by adding trailing singleton dimensions, if necessary, and returns the shape with more dimensions.

See Also

Array, broadcast, cat, combinations, conj!, digits!, fieldnames, fill, fill!, last, length, maximum, minimum, ones, parent, parentindexes, partitions, permutations, pointer, pointer_to_array, promote_shape, rand!, reshape, scale, similar, sum, sum_kbn, takebuf_array, transpose!, vec, zeros,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: