Creation#
- class ivy.data_classes.container.creation._ContainerWithCreation(dict_in=None, queues=None, queue_load_sizes=None, container_combine_method='list_join', queue_timeout=None, print_limit=10, key_length_limit=None, print_indent=4, print_line_spacing=0, ivyh=None, default_key_color='green', keyword_color_dict=None, rebuild_child_containers=False, types_to_iteratively_nest=None, alphabetical_keys=True, dynamic_backend=None, build_callable=False, **kwargs)[source]#
Bases:
ContainerBase
- _abc_impl = <_abc._abc_data object>#
- static _static_arange(start, /, stop=None, step=1, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- static _static_asarray(x, /, copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
ivy.Container static method variant of ivy.asarray. This method simply wraps the function, and so the docstring for ivy.asarray also applies to this method with minimal changes.
- Parameters:
self – input data, in any form that can be converted to an array. This includes lists, lists of tuples, tuples, tuples of tuples, tuples of lists and ndarrays.
copy (
Optional
[Union
[bool
,Container
]], default:None
) – boolean indicating whether or not to copy the input array. If True, the function must always copy. If False, the function must never copy and must raise a ValueError in case a copy would be necessary. If None, the function must reuse existing memory buffer if possible and copy otherwise. Default:None
.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – datatype, optional. Datatype is inferred from the input data.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to place the created array. Default:None
.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – An array interpretation of
self
.
Examples
With
ivy.Container
as input: >>> x = ivy.Container(a = [(1,2),(3,4),(5,6)], b = ((1,2,3),(4,5,6))) >>> ivy.asarray(x) {- a: ivy.array([[1, 2],
[3, 4], [5, 6]]),
- b: ivy.array([[1, 2, 3],
[4, 5, 6]])
}
- static _static_copy_array(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, to_ivy_array=True, out=None)[source]#
- Return type:
Container
- static _static_empty(shape, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- static _static_empty_like(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- static _static_eye(n_rows, n_cols=None, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, k=0, batch_shape=None, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- static _static_from_dlpack(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, out=None)[source]#
- Return type:
Container
- static _static_full(shape, fill_value, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, out=None, device=None)[source]#
- Return type:
Container
- static _static_full_like(x, /, fill_value, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
ivy.Container static method variant of ivy.full_like. This method simply wraps the function, and so the docstring for ivy.full_like also applies to this method with minimal changes.
- Parameters:
self – input container.
fill_value (
Union
[int
,float
,Container
]) – Scalar fill valuekey_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.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
is None, the output array data type must be inferred fromself
. Default:None
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to place the created array. Ifdevice
isNone
, the output array device must be inferred fromself
. Default:None
.
- Return type:
Container
- Returns:
ret – an output container having the same data type as
x
and whose elements, relative tox
, are shifted.
Examples
With
ivy.Container
input:>>> x = ivy.Container(a = ivy.array([1,2,3]) ,b = ivy.array([4,5,6])) >>> fill_value = 10 >>> y = ivy.Container.static_full_like(fill_value) { a: ivy.array([10, 10, 10]), b: ivy.array([10, 10, 10]) }
>>> x = ivy.Container(a=ivy.array([1.2, 2.2324, 3.234]), ... b=ivy.array([4.123, 5.23, 6.23])) >>> fill_value = 15.0 >>> y = ivy.Container.static_full_like(fill_value) >>> print(y) { a: ivy.array([15., 15., 15.]), b: ivy.array([15., 15., 15.]) }
- static _static_linspace(start, stop, /, num, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, axis=None, endpoint=True, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- static _static_logspace(start, stop, /, num, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, base=10.0, axis=0, endpoint=True, dtype=None, device=None, out=None)[source]#
ivy.Container static method variant of ivy.logspace. This method simply wraps the function, and so the docstring for ivy.logspace also applies to this method with minimal changes.
- Parameters:
start (
Union
[Array
,NativeArray
,float
,Container
]) – Container for first value in the range in log space.stop (
Union
[Array
,NativeArray
,float
,Container
]) – Container for last value in the range in log space.num (
Union
[int
,Container
]) – Number of values to generate.base (
Union
[float
,Container
], default:10.0
) – The base of the log space. Default is 10.0axis (
Union
[int
,Container
], default:0
) – Axis along which the operation is performed. Relevant only if values in start or stop containers are array-like. Default is 0.endpoint (
Union
[bool
,Container
], default:True
) – If True, stop is the last sample. Otherwise, it is not included. Default is True.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – The data type of the output tensor. If None, the dtype of on_value is used or if that is None, the dtype of off_value is used, or if that is None, defaults to float32. Default is None.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default is None.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Default is None.
- Return type:
Container
- Returns:
ret – a container having the same shape as
start
and filled with tensor of evenly-spaced values in log space.
Examples
>>> import ivy.container.creation.static_logspace as static_logspace >>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = static_logspace(x, y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) }
- static _static_meshgrid(*arrays, sparse=False, indexing='xy', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- static _static_native_array(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None)[source]#
- Return type:
Container
- static _static_one_hot(indices, depth, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, on_value=None, off_value=None, axis=None, dtype=None, device=None, out=None)[source]#
ivy.Container static method variant of ivy.one_hot. This method simply wraps the function, and so the docstring for ivy.one_hot also applies to this method with minimal changes.
- Parameters:
indices (
Container
) – Indices for where the ones should be scattered [batch_shape, dim]depth (
Union
[int
,Container
]) – Scalar defining the depth of the one-hot dimension.on_value (
Optional
[Union
[Number
,Container
]], default:None
) – Value to fill in output when indices[j] = i. If None, defaults to 1.off_value (
Optional
[Union
[Number
,Container
]], default:None
) – Value to fill in output when indices[j] != i. If None, defaults to 0.axis (
Optional
[Union
[int
,Container
]], default:None
) – Axis to scatter on. The default is-1
, a new inner-most axis is created.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – The data type of the output tensor. If None, defaults to the on_value dtype or the off_value dtype. If both are None, defaults to float32.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 is False.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
ret – container with tensors of zeros with the same shape and type as the inputs, unless dtype provided which overrides.
Examples
With
ivy.Container
inputs:>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 1]), c=ivy.array([2, 3])) >>> y = 5 >>> z = ivy.Container.static_one_hot(x, y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([[0., 0., 0., 1., 0.], [0., 1., 0., 0., 0.]]), c: ivy.array([[0., 0., 1., 0., 0.], [0., 0., 0., 1., 0.]]) }
>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([]), c=ivy.native_array([4])) >>> y = 5 >>> z = ivy.Container.static_one_hot(x, y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([], shape=(0, 5)), c: ivy.array([[0., 0., 0., 0., 1.]]) }
- static _static_ones(shape, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, out=None, dtype=None, device=None)[source]#
- Return type:
Container
- static _static_ones_like(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
ivy.Container static method variant of ivy.ones_like. This method simply wraps the function, and so the docstring for ivy.ones_like also applies to this method with minimal changes.
- Parameters:
x (
Union
[Array
,NativeArray
,Container
]) – input array from which to derive the output array shape.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
.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type must be inferred fromself
. DefaultNone
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to place the created array. If device isNone
, the output array device must be inferred fromself
. Default:None
.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container having the same shape as
self
and filled with ones.
- static _static_tril(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, k=0, out=None)[source]#
- Return type:
Container
- static _static_triu(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, k=0, out=None)[source]#
- Return type:
Container
- static _static_zeros(shape, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, out=None, dtype=None, device=None)[source]#
- Return type:
Container
- static _static_zeros_like(x, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
ivy.Container static method variant of ivy.zeros_like. This method simply wraps the function, and so the docstring for ivy.zeros_like also applies to this method with minimal changes.
- Parameters:
x (
Union
[Array
,NativeArray
,Container
]) – input array or container from which to derive the output container shape.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
.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output container data type must be inferred fromself
. DefaultNone
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to place the created array. If device isNone
, the output container device must be inferred fromself
. Default:None
.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 – an container having the same shape as
x
and filled withzeros
.
- asarray(copy=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- copy_array(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, to_ivy_array=True, out=None)[source]#
- Return type:
Container
- empty_like(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- from_dlpack(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, out=None)[source]#
- Return type:
Container
- frombuffer(dtype=<class 'float'>, count=-1, offset=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.frombuffer. This method simply wraps the function, and so the docstring for ivy.frombuffer also applies to this method with minimal changes.
- Parameters:
self (
Container
) – An object that exposes the buffer interface.dtype (
Optional
[Union
[Dtype
,NativeDtype
]], default:<class 'float'>
) – Data-type of the returned array; default: float.count (
Optional
[Union
[int
,Container
]], default:-1
) – Number of items to read. -1 means all data in the buffer.offset (
Optional
[Union
[int
,Container
]], default:0
) – Start reading the buffer from this offset (in bytes); default: 0.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 is False.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
out – 1-dimensional array.
Examples
With
ivy.Container
inputs:>>> x = ivy.Container( ... a = b'\x00\x00\x00\x00\x00\x00\xf0?', ... b = b'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@' ... ) >>> y = x.frombuffer(dtype=ivy.float64) >>> print(y) { a: ivy.array([1.]), b: ivy.array([1., 2.]) }
>>> x = ivy.Container( ... a = b'\x01\x02\x03\x04', ... b = b'\x05\x04\x03\x03\x02' ... ) >>> y = x.frombuffer(dtype=ivy.int8, count=3, offset=1) >>> print(y) { a: ivy.array([2, 3, 4]), b: ivy.array([4, 3, 3]) }
- full_like(fill_value, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, out=None, dtype=None, device=None)[source]#
ivy.Container instance method variant of ivy.full_like. This method simply wraps the function, and so the docstring for ivy.full_like also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container.fill_value (
Union
[int
,float
,Container
]) – Scalar fill valuekey_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.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
is None, the output array data type must be inferred fromself
. Default:None
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to place the created array. Ifdevice
isNone
, the output array device must be inferred fromself
. Default:None
.
- Return type:
Container
- Returns:
ret – an output container having the same data type as
x
and whose elements, relative tox
, are shifted.
Examples
With
ivy.Container
input:>>> x = ivy.Container(a = ivy.array([1,2,3]) ,b = ivy.array([4,5,6])) >>> fill_value = 10 >>> y = x.full_like(fill_value) { a: ivy.array([10, 10, 10]), b: ivy.array([10, 10, 10]) }
>>> x = ivy.Container(a=ivy.array([1.2,2.2324,3.234]), ... b=ivy.array([4.123,5.23,6.23])) >>> fill_value = 15.0 >>> y = x.full_like(fill_value) >>> print(y) { a: ivy.array([15., 15., 15.]), b: ivy.array([15., 15., 15.]) }
- linspace(stop, /, num, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, axis=None, endpoint=True, dtype=None, device=None, out=None)[source]#
- Return type:
Container
- logspace(stop, /, num, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, base=10.0, axis=None, endpoint=True, dtype=None, device=None, out=None)[source]#
ivy.Container instance method variant of ivy.logspace. This method simply wraps the function, and so the docstring for ivy.logspace also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Container for first value in the range in log space.stop (
Union
[Array
,NativeArray
,float
,Container
]) – Container for last value in the range in log space.num (
Union
[int
,Container
]) – Number of values to generate.base (
Union
[float
,Container
], default:10.0
) – The base of the log space. Default is 10.0axis (
Optional
[Union
[int
,Container
]], default:None
) – Axis along which the operation is performed. Relevant only if values in start or stop containers are array-like. Default is 0.endpoint (
Union
[bool
,Container
], default:True
) – If True, stop is the last sample. Otherwise, it is not included. Default is True.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – The data type of the output tensor. If None, the dtype of on_value is used or if that is None, the dtype of off_value is used, or if that is None, defaults to float32. Default is None.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to create the array ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. Default is None.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to. Default is None.
- Return type:
Container
- Returns:
ret – a container having the same shape as
self
and filled with tensor of evenly-spaced values in log space.
Examples
>>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = x.logspace(y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) }
>>> x = ivy.Container(a = 1, b = 0) >>> y = ivy.Container(a = 4, b = 1) >>> z = ivy.logspace(x, y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) }
>>> u = ivy.Container(c = 0, d = 0) >>> v = ivy.Container(c = 1, d = 2) >>> x = ivy.Container(a = 1, b = u) >>> y = ivy.Container(a = 4, b = v) >>> z = x.logspace(y, 4) { a: ivy.array([10., 100., 1000., 10000.]), b: { c: ivy.array([ 1., 2.15443469, 4.64158883, 10.]) d: ivy.array([ 1., 4.64158883, 21.5443469, 100.]) } }
- meshgrid(*arrays, sparse=False, indexing='xy', key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
- Return type:
Container
- native_array(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None)[source]#
- Return type:
Container
- one_hot(depth, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, on_value=None, off_value=None, axis=None, dtype=None, device=None, out=None)[source]#
ivy.Container instance method variant of ivy.one_hot. This method simply wraps the function, and so the docstring for ivy.one_hot also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Indices for where the ones should be scattered [batch_shape, dim]depth (
Union
[int
,Container
]) – Scalar defining the depth of the one-hot dimension.on_value (
Optional
[Union
[Number
,Container
]], default:None
) – Value to fill in output when indices[j] == i. If None, defaults to 1.off_value (
Optional
[Union
[Number
,Container
]], default:None
) – Value to fill in output when indices[j] != i. If None, defaults to 0.axis (
Optional
[Union
[int
,Container
]], default:None
) – Axis to scatter on. The default is-1
, a new inner-most axis is created.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – The dtype of the returned tensor. If None, defaults to the on_value dtype or the off_value dtype. If both are None, defaults to float32.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 is False.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 – container with tensors of zeros with the same shape and type as the inputs, unless dtype provided which overrides.
Examples
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([3, 1]), c=ivy.array([2, 3])) >>> y = 5 >>> z = x.one_hot(y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([[0., 0., 0., 1., 0.], [0., 1., 0., 0., 0.]]), c: ivy.array([[0., 0., 1., 0., 0.], [0., 0., 0., 1., 0.]]) }
>>> x = ivy.Container(a=ivy.array([1, 2]), b=ivy.array([]), c=ivy.native_array([4])) >>> y = 5 >>> z = x.one_hot(y) >>> print(z) { a: ivy.array([[0., 1., 0., 0., 0.], [0., 0., 1., 0., 0.]]), b: ivy.array([], shape=(0, 5)), c: ivy.array([[0., 0., 0., 0., 1.]]) }
- ones_like(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
ivy.Container instance method variant of ivy.ones_like. This method simply wraps the function, and so the docstring for ivy.ones_like also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array from which to derive the output array shape.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
.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output array data type must be inferred fromself
. DefaultNone
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to place the created array. If device isNone
, the output array device must be inferred fromself
. Default:None
.out (
Optional
[Container
], default:None
) – optional output array, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container having the same shape as
self
and filled with ones.
- static static_frombuffer(buffer, dtype=<class 'float'>, count=-1, offset=0, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container static method variant of ivy.frombuffer. This method simply wraps the function, and so the docstring for ivy.frombuffer also applies to this method with minimal changes.
- Parameters:
buffer (
Container
) – An object that exposes the buffer interface.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:<class 'float'>
) – Data-type of the returned array; default: float.count (
Optional
[Union
[int
,Container
]], default:-1
) – Number of items to read. -1 means all data in the buffer.offset (
Optional
[Union
[int
,Container
]], default:0
) – Start reading the buffer from this offset (in bytes); default: 0.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 is False.map_sequences (
Union
[bool
,Container
], default:False
) – Whether to also map method to sequences (lists, tuples). Default isFalse
.
- Return type:
Container
- Returns:
out – 1-dimensional array.
Examples
With
ivy.Container
inputs:>>> x = ivy.Container( ... a = b'\x00\x00\x00\x00\x00\x00\xf0?', ... b = b'\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@' ... ) >>> y = ivy.Container.static_frombuffer(x) >>> print(y) { a: ivy.array([1.]), b: ivy.array([1., 2.]) }
>>> x = ivy.Container( ... a = b'\x01\x02\x03\x04', ... b = b'\x05\x04\x03\x03\x02' ... ) >>> y = ivy.Container.static_frombuffer(x, dtype=ivy.int8, count=3, offset=1) >>> print(y) { a: ivy.array([2, 3, 4]), b: ivy.array([4, 3, 3]) }
- static static_triu_indices(n_rows, n_cols=None, k=0, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, device=None, out=None)[source]#
- Return type:
Container
- tril(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, k=0, out=None)[source]#
- Return type:
Container
- triu(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, k=0, out=None)[source]#
- Return type:
Container
- triu_indices(n_rows, n_cols=None, k=0, /, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, device=None, out=None)[source]#
- Return type:
Container
- zeros_like(key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, *, dtype=None, device=None, out=None)[source]#
ivy.Container instance method variant of ivy.zeros_like. This method simply wraps the function, and so the docstring for ivy.zeros_like also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input array or container from which to derive the output container shape.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
.dtype (
Optional
[Union
[Dtype
,NativeDtype
,Container
]], default:None
) – output array data type. Ifdtype
isNone
, the output container data type must be inferred fromself
. Default:None
.device (
Optional
[Union
[Device
,NativeDevice
,Container
]], default:None
) – device on which to place the created array. If device isNone
, the output container device must be inferred fromself
. Default:None
.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 – an container having the same shape as
x
and filled withzeros
.
This should have hopefully given you an overview of the creation submodule, if you have any questions, please feel free to reach out on our discord!