# zeros

Create array of all zeros for GPU or distributed arrays

## Syntax

``Z = zeros(n,arraytype)``
``Z = zeros(size1,...,sizeN,arraytype)``
``Z = zeros(size,arraytype)``
``Z = zeros(n,datatype,arraytype)``
``Z = zeros(size1,...,sizeN,datatype,arraytype)``
``Z = zeros(size,datatype,arraytype)``
``Z = zeros(n,'like',P)``
``Z = zeros(size1,...,sizeN,'like',P)``
``Z = zeros(size,'like',P)``
``Z = zeros(n,datatype,'like',P)``
``Z = zeros(size1,...,sizeN,datatype,'like',P)``
``Z = zeros(size,datatype,'like',P)``
``C = zeros(n,codist)``
``C = zeros(size1,...,sizeN,codist)``
``C = zeros(size,codist)``
``C = zeros(n,datatype,codist)``
``C = zeros(size1,...,sizeN,datatype,codist)``
``C = zeros(size,datatype,codist)``
``C = zeros(___,codist,'noCommunication')``
``C = zeros(___,codist,'like',P)``

## Description

example

````Z = zeros(n,arraytype)` returns an n-by-n matrix with underlying class of double, zeros in all elements, and the type specified by `arraytype`.```
````Z = zeros(size1,...,sizeN,arraytype)` returns a size1-by-...-by-sizeN matrix with underlying class of double, zeros in all elements, and the type specified by `arraytype`.```
````Z = zeros(size,arraytype)` returns an array whose size is defined by the size vector size with underlying class of double, zeros in all elements, and the type specified by `arraytype`.```

example

````Z = zeros(n,datatype,arraytype)` returns an n-by-n matrix with underlying class of `datatype`, zeros in all elements, and the type specified by `arraytype`.```
````Z = zeros(size1,...,sizeN,datatype,arraytype)` returns a size1-by-...-by-sizeN matrix with underlying class of `datatype`, zeros in all elements, and the type specified by `arraytype`.```
````Z = zeros(size,datatype,arraytype)` returns an array whose size is defined by the size vector size with underlying class of `datatype`, zeros in all elements, and the type specified by `arraytype`.```
````Z = zeros(n,'like',P)` returns an n-by-n array of zeros with the same underlying class and type as the prototype array, `P`.```
````Z = zeros(size1,...,sizeN,'like',P)` returns a size1-by-...-by-sizeN array of zeros with the same underlying class and type as the prototype array, `P`.```
````Z = zeros(size,'like',P)` returns an array of zeros whose size is defined by the size vector size with the same underlying class and type as the prototype array, `P`.```
````Z = zeros(n,datatype,'like',P)` returns an n-by-n array with underlying class of `datatype`, zeros in all elements, and the same type as the prototype array, `P`.```
````Z = zeros(size1,...,sizeN,datatype,'like',P)` returns a size1-by-...-by-sizeN array with underlying class of `datatype`, zeros in all elements, and the same type as the prototype array, `P`.```
````Z = zeros(size,datatype,'like',P)` returns an array whose size is defined by the size vector size with underlying class of `datatype`, zeros in all elements, and the same type as the prototype array, `P`.```
````C = zeros(n,codist)` returns an n-by-n codistributed array with underlying class of double and zeros in all elements. The codistributor object `codist` specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages for `codistributor1d` and `codistributor2dbc`.```
````C = zeros(size1,...,sizeN,codist)` returns a size1-by-...-by-sizeN codistributed array with underlying class of double and zeros in all elements. The codistributor object `codist` specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages for `codistributor1d` and `codistributor2dbc`.```
````C = zeros(size,codist)` returns a codistributed array whose size is defined by the size vector size with underlying class of double and zeros in all elements. The codistributor object `codist` specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages for `codistributor1d` and `codistributor2dbc`.```
````C = zeros(n,datatype,codist)` returns an n-by-n codistributed array with underlying class of `datatype` and zeros in all elements. The codistributor object `codist` specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages for `codistributor1d` and `codistributor2dbc`.```

example

````C = zeros(size1,...,sizeN,datatype,codist)` returns a size1-by-...-by-sizeN codistributed array with underlying class of `datatype` and zeros in all elements. The codistributor object `codist` specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages for `codistributor1d` and `codistributor2dbc`.```
````C = zeros(size,datatype,codist)` returns a codistributed array whose size is defined by the size vector size with underlying class of `datatype` and zeros in all elements. The codistributor object `codist` specifies the distribution scheme for creating the codistributed array. For information on constructing codistributor objects, see the reference pages for `codistributor1d` and `codistributor2dbc`.```
````C = zeros(___,codist,'noCommunication')` specifies that no interworker communication is to be performed when constructing a codistributed array, skipping some error checking steps. ```
````C = zeros(___,codist,'like',P)` creates a codistributed array of zeros with the specified size, underlying class, and distribution scheme. If either the class or codistributor argument is omitted, the characteristic is acquired from the codistributed array `P`.```

## Examples

collapse all

Create a 1000-by-1000 distributed array of zeros with underlying class double.

```D = zeros(1000,'distributed'); ```

Create a 1000-by-1000 codistributed double matrix of zeros, distributed by its second dimension (columns).

```spmd(4) C = zeros(1000,'codistributed'); end```

With four workers, each worker contains a 1000-by-250 local piece of `C`.

Create a 1000-by-1000 codistributed `uint16` matrix of zeros, distributed by its columns.

```spmd(4) codist = codistributor('1d',2,100*[1:numlabs]); C = zeros(1000,1000,'uint16',codist); end```

Each worker contains a 100-by-`labindex` local piece of `C`.

Create a 1000-by-1000 gpuArray of zeros, with underlying class `uint32`:

```G = zeros(1000,'uint32','gpuArray'); ```

## Input Arguments

collapse all

Size of the generated array, specified as an integer value.

Size of each dimension of the generated array, specified as separate arguments of two or more integer values.

Size of each dimension, specified as a row vector of integer values. Each element of this vector indicates the size of the corresponding dimension.

Type of the generated array, specified as either `'distributed'`, `'codistributed'`, or `'gpuArray'`.

Underlying class of the array, that is the data type of its elements, specified as one of these options:

• `'double'`

• `'single'`

• `'int8'`

• `'uint8'`

• `'int16'`

• `'uint16'`

• `'int32'`

• `'uint32'`

• `'int64'`

• `'uint64'`

Distribution scheme for creating the codistributed array, specified as a codistributor object. For information on constructing codistributor objects, see the reference pages for `codistributor1d` and `codistributor2dbc`. To use the default distribution scheme, you can specify a codistributor constructor without arguments.

Prototype of array to create, specified as an array.

## Output Arguments

collapse all

Array of zeros, returned as either a distributed array, a codistributed array, or a gpuArray.

Array of zeros, returned as a codistributed array. 