broadcast_arrays#
- ivy.broadcast_arrays(*arrays)[source]#
Broadcasts one or more arrays against one another.
- Parameters:
arrays (
Union
[Array
,NativeArray
]) – an arbitrary number of arrays to-be broadcasted.- Return type:
List
[Array
]- Returns:
ret – A list containing broadcasted arrays of type ivy.Array Each array must have the same shape, and each array must have the same dtype as its corresponding input array.
Examples
With
ivy.Array
input:>>> x1 = ivy.array([1, 2, 3]) >>> x2 = ivy.array([4, 5, 6]) >>> y = ivy.broadcast_arrays(x1, x2) >>> print(y) [ivy.array([1, 2, 3]), ivy.array([4, 5, 6])]
With
ivy.NativeArray
inputs:>>> x1 = ivy.native_array([0.3, 4.3]) >>> x2 = ivy.native_array([3.1, 5]) >>> x3 = ivy.native_array([2, 0]) >>> y = ivy.broadcast_arrays(x1, x2, x3) [ivy.array([0.3, 4.3]), ivy.array([3.1, 5.]), ivy.array([2, 0])]
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([1, 2]) >>> x2 = ivy.native_array([0.3, 4.3]) >>> y = ivy.broadcast_arrays(x1, x2) >>> print(y) [ivy.array([1, 2]), ivy.array([0.3, 4.3])]
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([3, 1]), b=ivy.zeros(2)) >>> x2 = ivy.Container(a=ivy.array([4, 5]), b=ivy.array([2, -1])) >>> y = ivy.broadcast_arrays(x1, x2) >>> print(y) [{ a: ivy.array([3, 1]), b: ivy.array([0., 0.]) }, { a: ivy.array([4, 5]), b: ivy.array([2, -1]) }]
With mixed
ivy.Array
andivy.Container
inputs:>>> x1 = ivy.zeros(2) >>> x2 = ivy.Container(a=ivy.array([4, 5]), b=ivy.array([2, -1])) >>> y = ivy.broadcast_arrays(x1, x2) >>> print(y) [{ a: ivy.array([0., 0.]), b: ivy.array([0., 0.]) }, { a: ivy.array([4, 5]), b: ivy.array([2, -1]) }]
- Array.broadcast_arrays(self, *arrays)[source]#
ivy.Array instance method variant of ivy.broadcast_arrays. This method simply wraps the function, and so the docstring for ivy.broadcast_arrays also applies to this method with minimal changes.
- Parameters:
self (
Array
) – An input array to be broadcasted against other input arrays.arrays (
Union
[Array
,NativeArray
]) – an arbitrary number of arrays to-be broadcasted. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.
- Return type:
List
[Array
]- Returns:
ret – A list containing broadcasted arrays of type ivy.Array
Examples
With
ivy.Array
inputs:>>> x1 = ivy.array([1, 2]) >>> x2 = ivy.array([0.2, 0.]) >>> x3 = ivy.zeros(2) >>> y = x1.broadcast_arrays(x2, x3) >>> print(y) [ivy.array([1, 2]), ivy.array([0.2, 0. ]), ivy.array([0., 0.])]
With mixed
ivy.Array
andivy.NativeArray
inputs:>>> x1 = ivy.array([-1., 3.4]) >>> x2 = ivy.native_array([2.4, 5.1]) >>> y = x1.broadcast_arrays(x2) >>> print(y) [ivy.array([-1., 3.4]), ivy.array([2.4, 5.1])]
- Container.broadcast_arrays(self, *arrays, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.broadcast_arrays. This method simply wraps the function, and so the docstring for ivy.broadcast_arrays also applies to this method with minimal changes.
- Parameters:
self (
Container
) – A container to be broadcatsed against other input arrays.arrays (
Union
[Container
,Array
,NativeArray
]) – an arbitrary number of containers having arrays to-be broadcasted. Each array must have the same shape. Each array must have the same dtype as its corresponding input array.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
],Container
]], default:None
) – The key-chains to apply or not apply the method to. Default isNone
.to_apply (
Union
[bool
,Container
], default:True
) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue
.prune_unapplied (
Union
[bool
,Container
], default:False
) – Whether to prune key_chains for which the function was not applied. Default isFalse
.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
Examples
With
ivy.Container
inputs:>>> x1 = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 4])) >>> x2 = ivy.Container(a=ivy.array([-1.2, 0.4]), b=ivy.array([0, 1])) >>> y = x1.broadcast_arrays(x2) >>> print(y) [{ a: ivy.array([1, 2]), b: ivy.array([3, 4]) }, { a: ivy.array([-1.2, 0.4]), b: ivy.array([0, 1]) }]
With mixed
ivy.Container
andivy.Array
inputs:>>> x1 = ivy.Container(a=ivy.array([4, 5]), b=ivy.array([2, -1])) >>> x2 = ivy.zeros(2) >>> y = x1.broadcast_arrays(x2) >>> print(y) [{ a: ivy.array([4, 5]), b: ivy.array([2, -1]) }, { a: ivy.array([0., 0.]), b: ivy.array([0., 0.]) }]