define dlarray data formats in matlab

To define a dlarray, you need to specify the data type, shape, and underlying data storage. Here's an example of how to create a dlarray with a 2x3x4x5 shape:

main.m
% create sample data
data = rand([2, 3, 4, 5]);
% define the data type and storage type
dataType = 'single';
storageType = 'cpu';
% create the dlarray
dlData = dlarray(data, 'SSCB', 'DataType', dataType, 'DataFormat', storageType);
232 chars
8 lines

In this example, we're using single precision (dataType = 'single') and storing the data on the CPU (storageType = 'cpu'). We're also specifying that the data is in "SSCB" order (samples, spatial dimensions, channels, batches) using the 'SSCB' option.

You can also create dlarrays with different storage formats, such as on a GPU ('gpu') or as a sparse array ('csparse'). The available options depend on your hardware and MATLAB installation.

For more information on creating and manipulating dlarrays, see the MATLAB documentation.

gistlibby LogSnag