nlcpy.empty_like

nlcpy.empty_like(prototype, dtype=None, order='K', subok=False, shape=None)[source]

Returns a new array with the same shape and type as a given array.

Parameters
prototypearray_like

The shape and dtype of prototype define these same attributes of the returned array.

dtypedtype, optional

Overrides the data type of the result.

order{‘C’, ‘F’}, optional

Overrides the memory layout of the result. ‘C’ means C-order, ‘F’ means F-order, ‘A’ means ‘F’ if prototype is Fortran contiguous, ‘C’ otherwise. ‘K’ means match the layout of prototype as closely as possible.

subokbool, optional

Not implemented.

shapeint or sequence of ints, optional

Overrides the shape of the result. If order=’K’ and the number of dimensions is unchanged, will try to keep order, otherwise, order=’C’ is implied.

Returns
outndarray

Array of uninitialized (arbitrary) data with the same shape and type as prototype.

See also

ones_like

Returns an array of ones with the same shape and type as a given array.

zeros_like

Returns an array of zeros with the same shape and type as a given array.

full_like

Returns a full array with the same shape and type as a given array.

empty

Returns a new array of given shape and type, without initializing entries.

Note

This function does not initialize the returned array; to do that use zeros_like() or ones_like() instead. It may be marginally faster than the functions that do set the array values.

Examples

>>> import nlcpy as vp
>>> a = ([1,2,3], [4,5,6])                         # a is array-like
>>> vp.empty_like(a)    
array([[0, 0, 0],
       [0, 0, 0]])                                 # uninitialized
>>> a = vp.array([[1., 2., 3.],[4.,5.,6.]])
>>> vp.empty_like(a)    
array([[0., 0., 0.],
       [0., 0., 0.]])                              # uninitialized