mindspore.dataset.transforms.c_transforms
This module c_transforms provides common operations, including OneHotOp and TypeCast.
- class mindspore.dataset.transforms.c_transforms.Concatenate(axis=0, prepend=None, append=None)[source]
Tensor operation to prepend and append to a tensor.
- Parameters
axis (int, optional) – axis to concatenate the tensors along (Default=0).
prepend (np.array, optional) – numpy array to be prepended to the already concatenated tensors (Default=None).
append (np.array, optional) – numpy array to be appended to the already concatenated tensors (Default=None).
- class mindspore.dataset.transforms.c_transforms.Duplicate[source]
Duplicate the input tensor to a new output tensor. The input tensor is carried over to the output list.
Examples
>>> # Data before >>> # | x | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------+ >>> data = data.map(input_columns=["x"], operations=Duplicate(), >>> output_columns=["x", "y"], columns_order=["x", "y"]) >>> # Data after >>> # | x | y | >>> # +---------+---------+ >>> # | [1,2,3] | [1,2,3] | >>> # +---------+---------+
- class mindspore.dataset.transforms.c_transforms.Fill(fill_value)[source]
Tensor operation to create a tensor filled with passed scalar value. The output tensor will have the same shape and type as the input tensor.
- class mindspore.dataset.transforms.c_transforms.Mask(operator, constant, dtype=mindspore.bool)[source]
Mask content of the input tensor with the given predicate. Any element of the tensor that matches the predicate will be evaluated to True, otherwise False.
- Parameters
operator (Relational) – One of the relational operator EQ, NE LT, GT, LE or GE
constant (python types (str, int, float, or bool) – constant to be compared to. Constant will be casted to the type of the input tensor
dtype (optional, mindspore.dtype) – type of the generated mask. Default to bool
Examples
>>> # Data before >>> # | col1 | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------+ >>> data = data.map(operations=Mask(Relational.EQ, 2)) >>> # Data after >>> # | col1 | >>> # +--------------------+ >>> # | [False,True,False] | >>> # +--------------------+
- class mindspore.dataset.transforms.c_transforms.OneHot(num_classes)[source]
Tensor operation to apply one hot encoding.
- Parameters
num_classes (int) – Number of classes of the label.
- class mindspore.dataset.transforms.c_transforms.PadEnd(pad_shape, pad_value=None)[source]
Pad input tensor according to pad_shape, need to have same rank.
- Parameters
pad_shape (list of int) – list on integers representing the shape needed. Dimensions that set to None will not be padded (i.e., original dim will be used). Shorter dimensions will truncate the values.
pad_value (python types (str, bytes, int, float, or bool), optional) – value used to pad. Default to 0 or empty string in case of Tensors of strings.
Examples
>>> # Data before >>> # | col | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------| >>> data = data.map(operations=PadEnd(pad_shape=[4], pad_value=10)) >>> # Data after >>> # | col | >>> # +------------+ >>> # | [1,2,3,10] | >>> # +------------|
- class mindspore.dataset.transforms.c_transforms.Slice(*slices)[source]
Slice operation to extract a tensor out using the given n slices.
The functionality of Slice is similar to NumPy indexing feature. (Currently only rank 1 Tensors are supported)
- Parameters
*slices (Variable length argument list) –
Maximum n number of arguments to slice a tensor of rank n. One object in slices can be one of:
int: slice this index only. Negative index is supported.
slice object: slice the generated indices from the slice object. Similar to start:stop:step.
None: slice the whole dimension. Similar to : in python indexing.
Ellipses …: slice all dimensions between the two slices.
Examples
>>> # Data before >>> # | col | >>> # +---------+ >>> # | [1,2,3] | >>> # +---------| >>> data = data.map(operations=Slice(slice(1,3))) # slice indices 1 and 2 only >>> # Data after >>> # | col | >>> # +------------+ >>> # | [1,2] | >>> # +------------|
- class mindspore.dataset.transforms.c_transforms.TypeCast(data_type)[source]
Tensor operation to cast to a given MindSpore data type.
- Parameters
data_type (mindspore.dtype) – mindspore.dtype to be casted to.