shuffle#
- ivy.shuffle(x, axis=0, /, *, seed=None, out=None)[source]#
Shuffles the given array along a given axis.
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array. Should have a numeric data type.axis (
Optional
[int
], default:0
) – The axis which x is shuffled along. Default is 0.seed (
Optional
[int
], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
- Returns:
ret – An array object, shuffled along the specified axis.
Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2, 3, 4, 5]) >>> y = ivy.shuffle(x) >>> print(y) ivy.array([2, 1, 4, 3, 5])
>>> x = ivy.array([1, 3, 5, 7]) >>> y = ivy.shuffle(x, seed=394) >>> print(y) ivy.array([3, 1, 5, 7])
>>> x = ivy.array([1, 0, 5]) >>> y = ivy.array([0, 0, 0]) >>> ivy.shuffle(x, seed=394, out=y) >>> print(y) ivy.array([0, 1, 5])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([5, 2, 9]), ... b=ivy.array([7, 1, 6])) >>> y = ivy.shuffle(x) >>> print(y) { a: ivy.array([5, 9, 2]), b: ivy.array([6, 1, 7]) }
>>> x = ivy.Container(a=ivy.array([7, 4, 5]), ... b=ivy.array([9, 8, 2])) >>> y = ivy.Container(a=ivy.array([0, 0, 0]), ... b=ivy.array([0, 0, 0])) >>> ivy.shuffle(x, seed=17, out=y) >>> print(y) { a: ivy.array([7, 5, 4]), b: ivy.array([9, 2, 8]) }
>>> x = ivy.Container(a=ivy.array([8, 2, 5]), ... b=ivy.array([3, 9, 0])) >>> ivy.shuffle(x, seed=17, out=x) >>> print(x) { a: ivy.array([2, 8, 5]), b: ivy.array([3, 0, 9]) }
- Array.shuffle(self, axis=0, /, *, seed=None, out=None)[source]#
ivy.Array instance method variant of ivy.shuffle. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes.
- Parameters:
self (
Array
) – Input array. Should have a numeric data type.axis (
Optional
[int
], default:0
) – The axis which x is shuffled along. Default is 0.seed (
Optional
[int
], default:None
) – A python integer. Used to create a random seed distributionout (
Optional
[Array
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Array
- Returns:
ret – An array object, shuffled along the first dimension.
Examples
>>> x = ivy.array([5, 2, 9]) >>> y = x.shuffle() >>> print(y) ivy.array([2, 5, 9])
- Container.shuffle(self, axis=0, /, *, seed=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.shuffle. This method simply wraps the function, and so the docstring for ivy.shuffle also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Input container. Should have a numeric data type.axis (
Optional
[Union
[int
,Container
]], default:0
) – The axis which input container is shuffled along. Default is 0.seed (
Optional
[Union
[int
,Container
]], default:None
) – A python integer. Used to create a random seed distributionkey_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
.out (
Optional
[Container
], default:None
) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – A container object, shuffled along the first dimension.
Examples
>>> x = ivy.Container(a=ivy.array([5, 2, 9]), ... b=ivy.array([7, 1, 6])) >>> y = ivy.Container.shuffle(x) >>> print(y) { a: ivy.array([9, 5, 2]), b: ivy.array([6, 7, 1]) }