Package org.nd4j.linalg.factory
Class Nd4j
- java.lang.Object
-
- org.nd4j.linalg.factory.Nd4j
-
public class Nd4j extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static DataBuffer.AllocationModeallocstatic Nd4jBackendbackendstatic NDBitwisebitwiseBitwise namespace - operations related to bitwise manipulation of arraysstatic NDCNNcnnConvolutional network namespace - operations related to convolutional neural networksstatic booleancompressDebugstatic StringDISTRIBUTIONprotected static DataTypedtypestatic StringDTYPEDeprecated.static doubleEPS_THRESHOLDstatic NDImageimageImage namespace - operations related to imagesprotected static NDArrayFactoryINSTANCEstatic NDLinalglinalgBitwise namespace - operations related to bitwise manipulation of arraysstatic StringLOG_INIT_ENV_PROPERTYDeprecated.static NDLosslossLoss function namespace - operations related to loss functions.static NDMathmathMath namespace - general mathematical operationsstatic StringNATIVE_OPSstatic NDNNnnNeural network namespace - operations related to neural networksstatic booleanpreventUnpackprotected static Propertiespropsstatic NDRandomrandomRandom namespace - (pseudo) random number generation methodsstatic RandomFactoryrandomFactorystatic NDRNNrnnRecurrent neural network namespace - operations related to recurrent neural networks
-
Constructor Summary
Constructors Constructor Description Nd4j()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static INDArrayaccumulate(@NonNull INDArray... arrays)This method sums given arrays and stores them to a new arraystatic INDArrayaccumulate(INDArray target, Collection<INDArray> arrays)This method sums given arrays and stores them to a given target arraystatic INDArrayaccumulate(INDArray target, INDArray[] arrays)This method sums given arrays and stores them to a given target arraystatic booleanallowsSpecifyOrdering()Backend specific: Returns whether specifying the order for the blas impl is allowed (cblas)static INDArrayappend(INDArray arr, int padAmount, double val, int axis)Append the given array with the specified value size along a particular axis.static INDArrayappendBias(@NonNull INDArray... vectors)static INDArrayarange(double end)Create a 1D array of evenly spaced values between 0 (inclusive) andend(exclusive) with a step size of 1 Seearange(double, double, double)with begin = 0 and step size 1.static INDArrayarange(double begin, double end)Create a 1D array of evenly spaced values betweenbegin(inclusive) andend(exclusive) with a step size of 1 Seearange(double, double, double)with step size 1.static INDArrayarange(double begin, double end, double step)Create a 1D array of evenly spaced values betweenbegin(inclusive) andend(exclusive) with a step size.static INDArrayargMax(INDArray arr, @lombok.NonNull int... dimension)Get the maximum values for a dimension.static INDArrayargMin(INDArray arr, @lombok.NonNull int... dimension)SeeargMax(INDArray, int...)but return minimum values.static INDArrayaverageAndPropagate(Collection<INDArray> arrays)This method averages input arrays, and returns averaged array.static INDArrayaverageAndPropagate(INDArray[] arrays)This method averages input arrays, and returns averaged array.static INDArrayaverageAndPropagate(INDArray target, Collection<INDArray> arrays)This method averages input arrays, and returns averaged array.static NDBitwisebitwise()Bitwise namespace - operations related to bitwise manipulation of arraysstatic voidcheckShapeValues(long... shape)Throws exception on negative shape values.static INDArraychoice(@NonNull INDArray source, @NonNull INDArray probs, @NonNull INDArray target, Random rng)This method samples value from Source array to Target, with probabilites provided in Probs argumentstatic INDArraychoice(INDArray source, INDArray probs, int numSamples)This method returns new INDArray instance, sampled from Source array with probabilities given in Probs using the default random number generator.static INDArraychoice(INDArray source, INDArray probs, int numSamples, Random rng)This method returns new INDArray instance, sampled from Source array with probabilities given in Probs.static INDArraychoice(INDArray source, INDArray probs, INDArray target)This method samples value from Source array to Target,the default random number generator.static voidclearNans(INDArray arr)Clear nans from an ndarraystatic NDCNNcnn()Convolutional network namespace - operations related to convolutional neural networksstatic INDArrayconcat(int dimension, @NonNull INDArray... toConcat)Concatenate ndarrays along a dimensionstatic org.bytedeco.javacpp.PointerconvertToNumpy(INDArray arr)Converts anINDArrayto a numpy struct.static voidcopy(INDArray a, INDArray b)Copy a to bstatic INDArraycreate(@lombok.NonNull int[] shape, char ordering)Creates an ndarray with the specified shapestatic INDArraycreate(@lombok.NonNull long[] shape, char ordering)Create an array with given shape and ordering.static INDArraycreate(boolean[] data)Create a vector based on a java boolean array.static INDArraycreate(boolean[][] data)Create 2D boolean array based on java 2d boolean array.static INDArraycreate(boolean[][] data, @lombok.NonNull long... shape)Create a boolean array with given shape based on java 2d boolean array.static INDArraycreate(boolean[] data, long[] shape, long[] strides, char order, DataType type)static INDArraycreate(boolean[] data, long[] shape, DataType type)static INDArraycreate(byte[] data, long[] shape, long[] strides, char order, DataType type)static INDArraycreate(byte[] data, long[] shape, DataType type)static INDArraycreate(double[] data)Create double array based on java double array.static INDArraycreate(double[][] data)Create 2D double array based on java 2d double array.static INDArraycreate(double[][][] data)Create a 3D double array based on the 3D java double array.static INDArraycreate(double[][][][] data)Create 4D double array based on 4D java double array.static INDArraycreate(double[][] data, char ordering)Create a 2D double array based on a 2D java double array with given ordering.static INDArraycreate(double[] data, char order)Creates a row vector with the datastatic INDArraycreate(double[] data, int[] shape)Create an array of the specified shape initialized with values from a java 1d array.static INDArraycreate(double[] data, int[] shape, char ordering)Create an array withgiven shape and ordering based on a java double array.static INDArraycreate(double[] data, int[] shape, long offset, char ordering)Create an array.static INDArraycreate(double[] data, long... shape)static INDArraycreate(double[] data, long[] shape, char ordering)static INDArraycreate(double[] data, long[] shape, long[] strides, char order, DataType type)static INDArraycreate(double[] data, long[] shape, long offset, char ordering)static INDArraycreate(double[] data, long[] shape, DataType type)static INDArraycreate(float[] data)Creates a row vector with the datastatic INDArraycreate(float[][] data)Create 2D float array based on java 2d float array.static INDArraycreate(float[][][] data)Create a 3D float array based on the 3D java float array.static INDArraycreate(float[][][][] data)Create 4D float array based on 4D java float array.static INDArraycreate(float[][] data, char ordering)Create 2D float array based on java 2d float array and ordering.static INDArraycreate(float[] data, char order)Creates a row vector with the datastatic INDArraycreate(float[] data, int[] shape)Create an ndrray with the specified shapestatic INDArraycreate(float[] data, int[] shape, char ordering)static INDArraycreate(float[] data, int[] shape, int[] stride, long offset)Create an array of the specified type, shape and stride initialized with values from a java 1d array using offset.static INDArraycreate(float[] data, long... shape)static INDArraycreate(float[] data, long[] shape, char ordering)static INDArraycreate(float[] data, long[] shape, long[] strides, char order, DataType type)static INDArraycreate(float[] data, long[] shape, DataType type)static INDArraycreate(int columns)Creates a row vector with the specified number of columnsstatic INDArraycreate(int... shape)Creates an ndarray with the specified shapestatic INDArraycreate(int[][] data)Create 2D double array based on java 2d double array.static INDArraycreate(int[][][] data)create 3D int array based on 3D java int array.static INDArraycreate(int[][][][] data)Create 4D int array based on 4D java int array.static INDArraycreate(int[] sliceShape, double[]... arrays)static INDArraycreate(int[] sliceShape, float[]... arrays)Create an ndarray based on the given datastatic INDArraycreate(int[] shape, int[] stride)Creates an ndarray with the specified shapestatic INDArraycreate(int[] shape, int[] stride, char ordering)Creates an ndarray with the specified shapestatic INDArraycreate(int[] shape, int[] stride, long offset)Creates an ndarray with the specified shapestatic INDArraycreate(int[] data, long[] shape, long[] strides, char order, DataType type)Create an array of the specified type, shape and stride initialized with values from a java 1d array.static INDArraycreate(int[] data, long[] shape, DataType type)Create an array of the specified type and shape initialized with values from a java 1d array.static INDArraycreate(int[] shape, DataType dataType)Create an array of given shape and data type.static INDArraycreate(int columns, char order)Creates a row vector with the specified number of columnsstatic INDArraycreate(int rows, int columns, int[] stride)Creates an ndarray with the specified shapestatic INDArraycreate(int rows, int columns, int[] stride, char ordering)Create a 2D array with given rows, columns, stride and ordering.static INDArraycreate(int rows, int columns, int[] stride, long offset)Creates an ndarray with the specified shapestatic INDArraycreate(long... shape)Creates an ndarray with the specified shapestatic INDArraycreate(long[][] data)Create 2D long array based on java 2d long array.static INDArraycreate(long[] shape, long[] stride)static INDArraycreate(long[] shape, long[] stride, char ordering)static INDArraycreate(long[] data, long[] shape, long[] strides, char order, DataType type)static INDArraycreate(long[] shape, long[] stride, long offset, char ordering)Creates an ndarray with the specified shapestatic INDArraycreate(long[] data, long[] shape, DataType type)static INDArraycreate(long rows, long columns, char ordering)Creates an ndarray with the specified shapestatic INDArraycreate(short[] data, long[] shape, long[] strides, char order, DataType type)static INDArraycreate(short[] data, long[] shape, DataType type)static INDArraycreate(@NonNull String... strings)static INDArraycreate(@NonNull Collection<String> strings, long... shape)static INDArraycreate(@NonNull Collection<String> strings, long[] shape, char order)static INDArraycreate(@NonNull DataType dataType, @lombok.NonNull long[] shape, char ordering)Create an array with given data type shape and ordering.static INDArraycreate(List<? extends Number> list)Creates a row vector with the datastatic INDArraycreate(List<INDArray> list, int... shape)Creates an array with the specified shape from a list of arrays.static INDArraycreate(List<INDArray> list, long... shape)static INDArraycreate(DataBuffer buffer)Create an array based on the data buffer.static INDArraycreate(DataBuffer data, int... shape)Create an array based on the data buffer with given shape.static INDArraycreate(DataBuffer data, int[] shape, int[] strides, long offset)Create an array based on the data buffer with given shape, stride and offset.static INDArraycreate(DataBuffer data, int[] newShape, int[] newStride, long offset, char ordering)static INDArraycreate(DataBuffer data, int[] shape, long offset)static INDArraycreate(DataBuffer data, long... shape)static INDArraycreate(DataBuffer data, long[] shape, long[] strides, long offset)static INDArraycreate(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering)static INDArraycreate(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering, DataType dataType)Create an array based on the data buffer with given shape, stride, offset and data type.static INDArraycreate(DataBuffer data, long[] newShape, long[] newStride, long offset, long ews, char ordering)Create an array based on the data buffer with given shape, stride and offset.static INDArraycreate(DataType dataType, @lombok.NonNull long[] shape, long[] strides, char ordering)Create an array with given shape, stride and ordering.static INDArraycreate(DataType type, long... shape)Create an array with specified shape and datatype.static INDArraycreate(LongShapeDescriptor descriptor)Seecreate(LongShapeDescriptor, boolean)with initialize set to true.static INDArraycreate(LongShapeDescriptor descriptor, boolean initialize)Create an ndarray based on the given description,static INDArraycreateArrayFromShapeBuffer(DataBuffer data, Pair<DataBuffer,long[]> shapeInfo)Create array based in data buffer and shape info,static INDArraycreateArrayFromShapeBuffer(DataBuffer data, DataBuffer shapeInfo)Create array based in data buffer and shape info,static DataBuffercreateBuffer(@lombok.NonNull int[] shape, @NonNull DataType type)Create a buffer equal of length prod(shape)static DataBuffercreateBuffer(@lombok.NonNull long[] shape, @NonNull DataType type)static DataBuffercreateBuffer(byte[] data, int length, long offset)Create a buffer based on the data opTypestatic DataBuffercreateBuffer(double[] data)static DataBuffercreateBuffer(double[] data, long offset)Create a buffer based on the data opTypestatic DataBuffercreateBuffer(float[] data)Create a buffer based on the data opTypestatic DataBuffercreateBuffer(float[] data, long offset)Create a buffer based on the data opTypestatic DataBuffercreateBuffer(int[] data)Create a buffer equal of length prod(shape)static DataBuffercreateBuffer(int[] shape, DataType type, long offset)Create a buffer equal of length prod(shape)static DataBuffercreateBuffer(int length, long offset)Creates a buffer of the specified length based on the data opTypestatic DataBuffercreateBuffer(long length)Creates a buffer of the specified length based on the data opTypestatic DataBuffercreateBuffer(long[] data)Create a buffer equal of length prod(shape)static DataBuffercreateBuffer(long length, boolean initialize)static DataBuffercreateBuffer(@NonNull org.bytedeco.javacpp.Pointer pointer, long length, @NonNull DataType dataType)Creates a buffer of the specified type and length with the given pointer.static DataBuffercreateBuffer(@NonNull org.bytedeco.javacpp.Pointer pointer, @NonNull org.bytedeco.javacpp.Pointer devicePointer, long length, @NonNull DataType dataType)Creates a buffer of the specified type and length with the given pointer at the specified device.static DataBuffercreateBuffer(ByteBuffer buffer, DataType type, int length)Creates a buffer of the specified opType and length with the given byte buffer.static DataBuffercreateBuffer(ByteBuffer buffer, DataType type, int length, long offset)Creates a buffer of the specified opType and length with the given byte buffer.static DataBuffercreateBuffer(org.bytedeco.javacpp.Pointer pointer, DataType type, long length, org.bytedeco.javacpp.indexer.Indexer indexer)Create a data buffer based on a pointer with the given opType and lengthstatic DataBuffercreateBuffer(DataBuffer underlyingBuffer, long offset, long length)Create a view of a data buffer Leverages the underlying storage of the buffer with a new viewstatic DataBuffercreateBuffer(DataType dataType, long length, boolean initialize)Create a data buffer based on datatype.static DataBuffercreateBuffer(DataType dataType, long length, boolean initialize, MemoryWorkspace workspace)Create a data buffer based on datatype, workspace.static DataBuffercreateBufferDetached(double[] data)static DataBuffercreateBufferDetached(float[] data)Create a buffer based on underlying array.static DataBuffercreateBufferDetached(int[] data)Create a buffer equal of length prod(shape).static DataBuffercreateBufferDetached(int[] shape, DataType type)Create a buffer equal of length prod(shape).static DataBuffercreateBufferDetached(long[] data)Create a buffer equal of length prod(shape).static DataBuffercreateBufferDetached(long[] shape, DataType type)static INDArraycreateFromArray(boolean... array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(boolean[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(boolean[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(boolean[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(byte... array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(byte[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(byte[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(byte[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(double... array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(double[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(double[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(double[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(float... array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(float[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(float[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(float[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(int... array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(int[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(int[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(int[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(long... array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(long[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(long[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(long[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(short... array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(short[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(short[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(short[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Boolean[] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Boolean[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Boolean[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Boolean[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Byte[] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Byte[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Byte[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Byte[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Double[] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Double[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Double[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Double[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Float[] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Float[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Float[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Float[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Integer[] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Integer[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Integer[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Integer[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Long[] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Long[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Long[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Long[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Short[] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Short[][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Short[][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromArray(Short[][][][] array)This method creates INDArray from provided jvm arraystatic INDArraycreateFromFlatArray(FlatArray array)static INDArraycreateFromNpyFile(@NonNull File file)Create an INDArray from a given Numpy .npy file.static INDArraycreateFromNpyPointer(org.bytedeco.javacpp.Pointer pointer)Create from an in memory numpy pointerstatic Map<String,INDArray>createFromNpzFile(File file)static INDArraycreateNpyFromByteArray(@lombok.NonNull byte[] input)Create anINDArrayfrom the given numpy input.
The numpy input follows the format: https://docs.scipy.org/doc/numpy-1.14.0/neps/npy-format.htmlstatic INDArraycreateNpyFromInputStream(@NonNull InputStream is)Create a numpy array based on the passed in input streamstatic DataBuffercreateTypedBuffer(boolean[] data, DataType dataType)static DataBuffercreateTypedBuffer(byte[] data, DataType dataType)static DataBuffercreateTypedBuffer(double[] data, DataType dataType)Create a buffer based on the data of the underlying java array with the specified type..static DataBuffercreateTypedBuffer(double[] data, DataType dataType, MemoryWorkspace workspace)Create a buffer based on the data of the underlying java array, specified type and workspacestatic DataBuffercreateTypedBuffer(float[] data, DataType dataType)static DataBuffercreateTypedBuffer(float[] data, DataType dataType, MemoryWorkspace workspace)static DataBuffercreateTypedBuffer(int[] data, DataType dataType)static DataBuffercreateTypedBuffer(long[] data, DataType dataType)static DataBuffercreateTypedBuffer(short[] data, DataType dataType)static DataBuffercreateTypedBufferDetached(boolean[] data, DataType dataType)static DataBuffercreateTypedBufferDetached(byte[] data, DataType dataType)static DataBuffercreateTypedBufferDetached(double[] data, DataType dataType)Create am uninitialized buffer based on the data of the underlying java array and specified type.static DataBuffercreateTypedBufferDetached(float[] data, DataType dataType)static DataBuffercreateTypedBufferDetached(int[] data, DataType dataType)static DataBuffercreateTypedBufferDetached(long[] data, DataType dataType)static DataBuffercreateTypedBufferDetached(short[] data, DataType dataType)static INDArraycreateUninitialized(int... shape)static INDArraycreateUninitialized(int[] shape, char ordering)Creates an *uninitialized* array with the specified shape and ordering.
NOTE: The underlying memory (DataBuffer) will not be initialized.static INDArraycreateUninitialized(long length)This method creates an *uninitialized* ndarray of specified length and default ordering.static INDArraycreateUninitialized(long... shape)Creates an *uninitialized* ndarray with the specified shape and default ordering.
NOTE: The underlying memory (DataBuffer) will not be initialized.static INDArraycreateUninitialized(long[] shape, char ordering)Creates an *uninitialized* array with the specified shape and ordering.static INDArraycreateUninitialized(DataType type, long... shape)static INDArraycreateUninitialized(DataType type, long[] shape, char ordering)Creates an *uninitialized* array with the specified data type, shape and ordering.static INDArraycreateUninitializedDetached(DataType dataType, char ordering, long... shape)Create an uninitialized ndArray.static INDArraycreateUninitializedDetached(DataType dataType, long... shape)SeecreateUninitializedDetached(DataType, char, long...)with default ordering.static INDArraycumsum(INDArray compute)SeeINDArray.cumsum(int)with Integer.MAX_VALUE for full array reduction.static INDArraycumsum(INDArray compute, int dimension)SeeINDArray.cumsum(int)with Integer.MAX_VALUE for full array reduction.static DataTypedataType()Returns the data opType used for the runtimestatic DataTypedefaultFloatingPointType()static INDArraydiag(INDArray x)Creates a new matrix where the values of the given vector are the diagonal values of the matrix if a vector is passed in, if a matrix is returns the kth diagonal in the matrixstatic INDArrayempty()This method creates "empty" INDArray with datatype determined bydataType()static INDArrayempty(DataType type)This method creates "empty" INDArray of the specified datatypestatic voidenableFallbackMode(boolean reallyEnable)This method enables fallback to safe-mode for specific operations.static INDArray[]exec(CustomOp op)Execute the operation and return the resultstatic INDArray[]exec(CustomOp op, OpContext context)Execute the operation and return the resultstatic INDArrayexec(Op op)Execute the operation and return the resultstatic INDArrayexec(Op op, OpContext context)static INDArrayexpandDims(INDArray input, int dimension)Expand the array dimensions.static INDArrayeye(long n)Create the identity ndarraystatic NDArrayFactoryfactory()The factory used for creating ndarraysstatic INDArrayfromByteArray(@lombok.NonNull byte[] arr)Read an ndarray from a byte arraystatic INDArraygemm(INDArray a, INDArray b, boolean transposeA, boolean transposeB)matrix multiply: implements op(a)*op(b) where op(x) means transpose x (or not) depending on setting of arguments transposea and transposeb.
so gemm(a,b,false,false) == a.mmul(b), gemm(a,b,true,false) == a.transpose().mmul(b) etc.static INDArraygemm(INDArray a, INDArray b, INDArray c, boolean transposeA, boolean transposeB, double alpha, double beta)Matrix multiply: Implements c = alpha*op(a)*op(b) + beta*c where op(X) means transpose X (or not) depending on setting of arguments transposeA and transposeB.
Note that matrix c MUST be fortran order, have zero offset and have c.data().length == c.length().static AffinityManagergetAffinityManager()static Nd4jBackendgetBackend()Retrieve the Nd4J backend.static BlasWrappergetBlasWrapper()Retrieve the BLAS wrapper.static BasicNDArrayCompressorgetCompressor()This method returns BasicNDArrayCompressor instance, suitable for NDArray compression/decompression at runtimestatic ConstantHandlergetConstantHandler()static ConvolutionInstancegetConvolution()Get the convolution singletonstatic DataBufferFactorygetDataBufferFactory()Get the data buffer factory instance.static DeallocatorServicegetDeallocatorService()static DistributionFactorygetDistributions()Get the primary distributions factorystatic EnvironmentgetEnvironment()Get the backend Environment instancestatic OpExecutionergetExecutioner()Get the operation executioner instance.static MemoryManagergetMemoryManager()This method returns backend-specific MemoryManager implementation, for low-level memory managementstatic NDArrayFactorygetNDArrayFactory()static RandomgetRandom()Get the current random generatorstatic RandomFactorygetRandomFactory()Get the RandomFactory instancestatic ShapeInfoProvidergetShapeInfoProvider()static int[]getStrides(@lombok.NonNull int... shape)Get the strides based on the shape and NDArrays.order()static long[]getStrides(@lombok.NonNull long... shape)Get the strides based on the shape and NDArrays.order()static int[]getStrides(int[] shape, char order)Get the strides for the given order and shapestatic long[]getStrides(long[] shape, char order)static MemoryWorkspaceManagergetWorkspaceManager()This method returns WorkspaceManager implementation to be used within this JVM processstatic INDArrayhstack(@NonNull INDArray... arrs)Concatenates two matrices horizontally.static INDArrayhstack(Collection<INDArray> arrs)Concatenates two matrices horizontally.static NDImageimage()Image namespace - operations related to imagesvoidinitWithBackend(Nd4jBackend backend)Initialize with the specific backendstatic booleanisExperimentalMode()static booleanisFallbackModeEnabled()This method checks, if fallback mode was enabled.static booleanisPrecisionBoostAllowed()static NDLinalglinalg()Linalg namespace - operations related to linear algebra (lapack operations)static INDArraylinspace(double lower, double upper, long num, @NonNull DataType dataType)Generate a linearly spaced 1d vector of the specified datatypestatic INDArraylinspace(long lower, long upper, long num)Generate a linearly spaced vector with default data typestatic INDArraylinspace(long lower, long upper, long num, @NonNull DataType dtype)Generate a linearly spaced vectorstatic INDArraylinspace(@NonNull DataType dataType, double lower, double step, long num)Generate a linearly spaced 1d vector of the specified datatypestatic INDArraylinspace(@NonNull DataType dtype, long lower, long num, long step)Generate a linearly spaced vectorstatic NDLossloss()Loss function namespace - operations related to loss functions.static NDMathmath()Math namespace - general mathematical operationsstatic INDArraymatmul(INDArray a, INDArray b)Matrix multiplication/dot product Seematmul(INDArray, INDArray, INDArray, boolean, boolean, boolean)static INDArraymatmul(INDArray a, INDArray b, boolean transposeA, boolean transposeB, boolean transposeResult)Matrix multiplication/dot product.
Seematmul(INDArray, INDArray, INDArray, boolean, boolean, boolean)static INDArraymatmul(INDArray a, INDArray b, INDArray result)Matrix multiplication/dot product.
Seematmul(INDArray, INDArray, INDArray, boolean, boolean, boolean)static INDArraymatmul(INDArray a, INDArray b, INDArray result, boolean transposeA, boolean transposeB, boolean transposeResult)Matrix multiplication/dot product Depending on inputs dimensionality output result might be different.static INDArraymax(INDArray compute)SeeINDArray.max(int...)with Integer.MAX_VALUE for full array reduction.static INDArraymax(INDArray compute, int dimension)SeeINDArray.max(int...)with Integer.MAX_VALUE for full array reduction.static INDArraymean(INDArray compute)SeeINDArray.mean(int...)with Integer.MAX_VALUE for full array reduction.static INDArraymean(INDArray compute, int dimension)SeeINDArray.mean(int...)with Integer.MAX_VALUE for full array reduction.static INDArray[]meshgrid(@NonNull INDArray x, @NonNull INDArray y)Meshgrid op.static INDArraymin(INDArray compute)SeeINDArray.min(int...)with Integer.MAX_VALUE for full array reduction.static INDArraymin(INDArray compute, int dimension)SeeINDArray.min(int...)with Integer.MAX_VALUE for full array reduction.static NDNNnn()Neural network namespace - operations related to neural networksstatic INDArraynorm1(INDArray compute)SeeINDArray.norm1(int...)with Integer.MAX_VALUE for full array reduction.static INDArraynorm1(INDArray compute, int dimension)SeeINDArray.norm1(int...)with Integer.MAX_VALUE for full array reduction.static INDArraynorm2(INDArray compute)SeeINDArray.norm2(int...)with Integer.MAX_VALUE for full array reduction.static INDArraynorm2(INDArray compute, int dimension)SeeINDArray.norm2(int...)with Integer.MAX_VALUE for full array reduction.static INDArraynormmax(INDArray compute)SeeINDArray.normmax(int...)with Integer.MAX_VALUE for full array reduction.static INDArraynormmax(INDArray compute, int dimension)SeeINDArray.normmax(int...)with Integer.MAX_VALUE for full array reduction.static INDArrayones(@lombok.NonNull int... shape)Create an ndarray of onesstatic INDArrayones(@lombok.NonNull long... shape)static INDArrayones(DataType dataType, @lombok.NonNull long... shape)Creates an array with the specified datatype and shape, with values all set to 1static INDArrayonesLike(INDArray arr)Ones likestatic Characterorder()Returns the ordering of the ndarraysstatic INDArraypad(@NonNull INDArray toPad, @lombok.NonNull int... padWidth)static INDArraypad(@NonNull INDArray toPad, @lombok.NonNull int[][] padWidth)static INDArraypad(@NonNull INDArray toPad, @lombok.NonNull int[][] padWidth, Pad.Mode padMode, double padValue)static INDArraypad(@NonNull INDArray toPad, @lombok.NonNull int[] padWidth, Pad.Mode padMode, double padValue)Seepad(INDArray, INDArray, Mode, double), uses padWidth for all dimensions.static INDArraypad(@NonNull INDArray toPad, @NonNull INDArray padWidth, Pad.Mode padMode, double padValue)Pad the given ndarray to the size along each dimension.static INDArraypad(INDArray toPad, INDArray padding)Seepad(INDArray, INDArray, Mode, double)with zero padding (zeros for padValue).static INDArraypile(@NonNull Collection<INDArray> arrays)This method stacks vertically examples with the same shape, increasing result dimensionality.static INDArraypile(@NonNull INDArray... arrays)This method stacks vertically examples with the same shape, increasing result dimensionality.static INDArrayprepend(INDArray arr, int padAmount, double val, int axis)static INDArrayprod(INDArray compute)SeeINDArray.prod(int...)with Integer.MAX_VALUE for full array reduction.static INDArrayprod(INDArray compute, int dimension)SeeINDArray.prod(int...)with Integer.MAX_VALUE for full array reduction.static INDArraypullRows(INDArray source, int sourceDimension, @lombok.NonNull int... indexes)This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexesstatic INDArraypullRows(INDArray source, int sourceDimension, int[] indexes, char order)This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexesstatic INDArraypullRows(INDArray source, INDArray destination, int sourceDimension, @lombok.NonNull int... indexes)This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes.static INDArrayrand(@lombok.NonNull int... shape)Create a random ndarray with values from a uniform distribution over (0, 1) with the given shapestatic INDArrayrand(@lombok.NonNull long... shape)Seerand(int[])static INDArrayrand(char order, @lombok.NonNull int... shape)Create a random ndarray with the given shape and array order Values are sampled from a uniform distribution over (0, 1)static INDArrayrand(double min, double max, Random rng, @lombok.NonNull long... shape)Generates a random matrix between min and maxstatic INDArrayrand(int[] shape, double min, double max, Random rng)Deprecated.static INDArrayrand(int[] shape, long seed)Deprecated.static INDArrayrand(int[] shape, @NonNull Distribution dist)Deprecated.static INDArrayrand(int[] shape, Random rng)Deprecated.static INDArrayrand(int rows, int columns, Random rng)Create a random ndarray with the given shape using the given rngstatic INDArrayrand(long[] shape, double min, double max, Random rng)Deprecated.static INDArrayrand(long[] shape, @NonNull Distribution dist)Deprecated.static INDArrayrand(long seed, @lombok.NonNull long... shape)Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape using given seedstatic INDArrayrand(@NonNull DataType dataType, @lombok.NonNull int... shape)Create a random ndarray with the given shape and data type Values are sampled from a uniform distribution over (0, 1)static INDArrayrand(@NonNull DataType dataType, @lombok.NonNull long... shape)Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape and data typestatic INDArrayrand(@NonNull DataType dataType, char order, @lombok.NonNull int... shape)Deprecated.static INDArrayrand(@NonNull DataType dataType, char order, @lombok.NonNull long... shape)Create a random ndarray with the given shape, data type, and array order Values are sampled from a uniform distribution over (0, 1)static INDArrayrand(@NonNull DataType dataType, int[] shape, char order)Deprecated.use {@link Nd4j#rand(DataType, char, long...))static INDArrayrand(@NonNull Distribution dist, @lombok.NonNull long... shape)Create a random ndarray with the given shape using the given rngstatic INDArrayrand(INDArray target)Fill the given ndarray with random numbers drawn from a uniform distributionstatic INDArrayrand(INDArray target, double min, double max, Random rng)Fill the given ndarray with random numbers drawn from a uniform distribution using the given RandomGeneratorstatic INDArrayrand(INDArray target, long seed)Fill the given ndarray with random numbers drawn from a uniform distributionstatic INDArrayrand(INDArray target, @NonNull Distribution dist)Fill the given ndarray with random numbers drawn from the given distributionstatic INDArrayrand(INDArray target, Random rng)Fill the given ndarray with random numbers drawn from a uniform distribution using the given RandomGeneratorstatic INDArrayrand(Random rng, @lombok.NonNull long... shape)Create a random ndarray with the given shape using the given RandomGeneratorstatic INDArrayrandn(@lombok.NonNull int[] shape)Create a ndarray of the given shape with values from N(0,1)static INDArrayrandn(@lombok.NonNull long... shape)Create a ndarray of the given shape with values from N(0,1).static INDArrayrandn(char order, @lombok.NonNull int... shape)Random normal N(0,1) with the specified shape and array orderstatic INDArrayrandn(char order, @lombok.NonNull long... shape)Random normal N(0,1) with the specified shape and array orderstatic INDArrayrandn(double mean, double stddev, long[] shape, Random rng)static INDArrayrandn(double mean, double stddev, INDArray target, Random rng)static INDArrayrandn(int[] shape, Random r)Deprecated.static INDArrayrandn(long[] shape, Random r)Deprecated.static INDArrayrandn(long seed, @lombok.NonNull long[] shape)Random normal N(0, 1) using the specified seedstatic INDArrayrandn(long seed, int[] shape)Deprecated.static INDArrayrandn(@NonNull DataType dataType, @lombok.NonNull int[] shape)Create a ndarray of the given shape and data type with values from N(0,1)static INDArrayrandn(@NonNull DataType dataType, @lombok.NonNull long... shape)Create a ndarray of the given shape and data type with values from N(0,1)static INDArrayrandn(@NonNull DataType dataType, char order, @lombok.NonNull long... shape)Random normal N(0,1) with the specified shape and array orderstatic INDArrayrandn(INDArray target)Fill the given ndarray with random numbers drawn from a normal distributionstatic INDArrayrandn(INDArray target, long seed)Fill the given ndarray with random numbers drawn from a normal distributionstatic INDArrayrandn(INDArray target, Random rng)Fill the given ndarray with random numbers drawn from a normal distribution utilizing the given random generatorstatic INDArrayrandn(Random r, @lombok.NonNull long... shape)Random normal using the given rngstatic NDRandomrandom()Random namespace - (pseudo) random number generation methodsstatic INDArrayrandomBernoulli(double p, @lombok.NonNull long... shape)Generate a random array according to a binomial distribution with probability p: i.e., values 0 with probability (1-p) or value 1 with probability pstatic INDArrayrandomBernoulli(double p, @NonNull INDArray target)Fill the specified array with values generated according to a binomial distribution with probability p: i.e., values 0 with probability (1-p) or value 1 with probability pstatic INDArrayrandomBinomial(int nTrials, double p, @lombok.NonNull long... shape)Generate an array with random values generated according to a binomial distribution with the specified number of trials and probabilitystatic INDArrayrandomBinomial(int nTrials, double p, INDArray target)Fill the target array with random values generated according to a binomial distribution with the specified number of trials and probabilitystatic INDArrayrandomExponential(double lambda, long... shape)Exponential distribution: P(x) = lambda * exp(-lambda * x)static INDArrayrandomExponential(double lambda, INDArray target)Exponential distribution: P(x) = lambda * exp(-lambda * x)static INDArrayread(DataInputStream dis)Read in an ndarray from a data input streamstatic INDArrayread(InputStream reader)Raad an ndarray from an input stream Seeread(DataInputStream)static INDArrayreadBinary(File read)Read a binary ndarray from the given filestatic INDArrayreadNpy(@NonNull File file)Create an INDArray from a given Numpy .npy file.static INDArrayreadNpy(@NonNull String path)Create an INDArray from a given Numpy .npy file.static INDArrayreadNumpy(@NonNull InputStream filePath, @NonNull String split)Read line via input streamsstatic INDArrayreadNumpy(@NonNull DataType dataType, @NonNull InputStream filePath, @NonNull String split, @NonNull Charset charset)Read array from input stream.static INDArrayreadNumpy(String filePath)Read line via input streamsstatic INDArrayreadNumpy(String filePath, String split)Read line via input streamsstatic INDArrayreadNumpy(DataType dataType, String filePath)Read array.
SeereadNumpy(DataType, InputStream, String , Charset)with default split and UTF-8 encoding.static INDArrayreadNumpy(DataType dataType, String filePath, String split)Read array via input stream.static INDArrayreadTxt(String filePath)Deprecated.to be removed in 1.0static INDArrayreadTxtString(InputStream ndarray)Deprecated.To be removed in 1.0static INDArrayrepeat(INDArray n, int num)Create an n x (shape) ndarray where the ndarray is repeated num timesstatic INDArrayreverse(INDArray reverse)Reverses the passed in matrix such that m[0] becomes m[m.length - 1] etcstatic NDRNNrnn()Recurrent neural network namespace - operations related to recurrent neural networksstatic INDArrayrollAxis(INDArray a, int axis)Roll the specified axis backwards, until it lies in a given position.static INDArrayrollAxis(INDArray a, int axis, int start)Roll the specified axis backwards, until it lies in a given position.static voidrot90(INDArray toRotate)Rotate a matrix 90 degreesstatic voidsaveBinary(INDArray arr, File saveTo)Save an ndarray to the given filestatic INDArrayscalar(boolean value)Create a scalar NDArray with the specified value and BOOLEAN datatypestatic INDArrayscalar(double value)Create a scalar nd array with the specified valuestatic INDArrayscalar(float value)Create a scalar NDArray with the specified value and FLOAT datatypestatic INDArrayscalar(int value)Create a scalar NDArray with the specified value and INT datatypestatic INDArrayscalar(long value)Create a scalar NDArray with the specified value and LONG datatypestatic INDArrayscalar(@NonNull String string)static INDArrayscalar(Number value)Create a scalar ndarray with the specified valuestatic INDArrayscalar(DataType dataType, Number value)Create a scalar ndarray with the specified value and datatypestatic voidscatterUpdate(ScatterUpdate.UpdateOp op, @NonNull INDArray array, @NonNull INDArray indices, @NonNull INDArray updates, int... axis)Deprecated.static voidsetConvolution(ConvolutionInstance convolutionInstance)Set a convolution instancestatic voidsetDataType(@NonNull DataType dtype)Deprecated.static voidsetDefaultDataTypes(@NonNull DataType defaultType, @NonNull DataType defaultFloatingPointType)Set the default data types.
The default data types are used for array creation methods where no data type is specified.
When the user explicitly provides a datatype (such as in Nd4j.ones(DataType.FLOAT, 1, 10)) these default values will not be used.
defaultType: used in methods such as Nd4j.ones(1,10) and Nd4j.zeros(10).
defaultFloatingPointType: used internally where a floating point array needs to be created, but no datatype is specified.static voidsetFactory(NDArrayFactory factory)Set the factory instance for INDArray creation.static long[]shape(INDArray arr)Returns the shape of the ndarraystatic voidshuffle(Collection<INDArray> toShuffle, @lombok.NonNull int... dimension)Symmetric in place shuffle of an ndarray along a specified set of dimensionsstatic voidshuffle(Collection<INDArray> toShuffle, Random rnd, @lombok.NonNull int... dimension)Symmetric in place shuffle of an ndarray along a specified set of dimensionsstatic voidshuffle(List<INDArray> toShuffle, Random rnd, List<int[]> dimensions)Symmetric in place shuffle of an ndarray along a variable dimensionsstatic voidshuffle(INDArray toShuffle, @lombok.NonNull int... dimension)In place shuffle of an ndarray along a specified set of dimensionsstatic voidshuffle(INDArray toShuffle, Random random, @lombok.NonNull int... dimension)In place shuffle of an ndarray along a specified set of dimensionsstatic intsizeOfDataType()Deprecated.Use DataType.width()static intsizeOfDataType(DataType dtype)This method returns size of element for specified dataType, in bytesstatic INDArraysort(INDArray ndarray, boolean ascending)Sort all elements of an array.static INDArraysort(INDArray ndarray, int dimension, boolean ascending)Sort an ndarray along a particular dimension
Note that the input array is modified in-place.static INDArraysortColumns(INDArray in, int rowIdx, boolean ascending)Sort (shuffle) the columns of a 2d array according to the value at a specified row.static INDArraysortRows(INDArray in, int colIdx, boolean ascending)Sort (shuffle) the rows of a 2d array according to the value at a specified column.static INDArray[]sortWithIndices(INDArray ndarray, int dimension, boolean ascending)Sort an ndarray along a particular dimension.
Note that the input array is modified in-place.static INDArrayspecialConcat(int dimension, @NonNull INDArray... toConcat)Concatenate ndarrays along a dimension PLEASE NOTE: This method is special for GPU backend, it works on HOST side only.static INDArraysqueeze(INDArray input, int dimension)Squeeze : removes a dimension of size 1static INDArraystack(int axis, @NonNull INDArray... values)Stack a set of N SDVariables of rank X into one rank X+1 variable.static INDArraystd(INDArray compute)SeeINDArray.std(int...)with Integer.MAX_VALUE for full array reduction.static INDArraystd(INDArray compute, int dimension)SeeINDArray.std(int...)with Integer.MAX_VALUE for full array reduction.static INDArraystripOnes(INDArray toStrip)Reshapes an ndarray to remove leading 1sstatic INDArraysum(INDArray compute)SeeINDArray.sum(int...)with Integer.MAX_VALUE for full array reduction.static INDArraysum(INDArray compute, int dimension)SeeINDArray.sum(int...)with Integer.MAX_VALUE for full array reduction.static INDArray[]tear(INDArray tensor, @lombok.NonNull int... dimensions)This method does the opposite to pile/vstack/hstack - it returns independent TAD copies along given dimensionsstatic INDArraytensorMmul(INDArray a, INDArray b, int[][] axes)Tensor matrix multiplication.static INDArraytensorMmul(INDArray a, INDArray b, INDArray result, int[][] axes)Tensor matrix multiplication.static INDArraytile(INDArray tile, @lombok.NonNull int... repeat)An alias for repmatstatic byte[]toByteArray(@NonNull INDArray arr)Convert an ndarray to a byte arraystatic INDArraytoFlattened(char order, @NonNull INDArray... matrices)Create a long row vector of all of the given ndarrays/static INDArraytoFlattened(char order, Collection<INDArray> matrices)Create a long row vector of all of the given ndarraysstatic INDArraytoFlattened(@NonNull INDArray... matrices)Create a long row vector of all of the given ndarraysstatic INDArraytoFlattened(Collection<INDArray> matrices)Create a long row vector of all of the given ndarraysstatic byte[]toNpyByteArray(INDArray input)Converts anINDArrayto a byte arraystatic INDArraytri(int n)Seetri(int,int,int)with m = n, k=0.static INDArraytri(int n, int k)Seetri(int,int,int)with m = n.static INDArraytri(int n, int m, int k)Like the scipy function tri.static INDArraytriu(INDArray m, int k)Upper triangle of an array.static INDArrayvalueArrayOf(int[] shape, double value)Creates an ndarray with the specified value as the only value in the ndarray.static INDArrayvalueArrayOf(long[] shape, double value)static INDArrayvalueArrayOf(long[] shape, double value, DataType type)Creates an ndarray with the specified value as the only value in the ndarray.static INDArrayvalueArrayOf(long[] shape, float value)Creates an ndarray with the specified value as the only value in the FLOAT32 datatype NDArray.static INDArrayvalueArrayOf(long[] shape, int value)Creates an ndarray with the specified value as the only value in the INTEGER datatype NDArray.static INDArrayvalueArrayOf(long[] shape, long value, DataType type)static INDArrayvalueArrayOf(long num, double value)Creates a row vector ndarray with the specified value as the only value in the ndarray Some people may know this as np.fullstatic INDArrayvalueArrayOf(long rows, long columns, double value)Creates a row vector with the specified number of columns Some people may know this as np.fullstatic INDArrayvar(INDArray compute)SeeINDArray.var(int...)with Integer.MAX_VALUE for full array reduction.static INDArrayvar(INDArray compute, int dimension)SeeINDArray.var(int...)with Integer.MAX_VALUE for full array reduction.static INDArrayvstack(@NonNull INDArray... arrs)Concatenates two matrices vertically.static INDArrayvstack(Collection<INDArray> arrs)Concatenates two matrices vertically.static INDArray[]where(INDArray condition, INDArray x, INDArray y)Similar to numpy.where operation.static voidwrite(OutputStream writer, INDArray write)Y Write an ndarray to a writerstatic voidwrite(INDArray arr, DataOutputStream dataOutputStream)Write an ndarray to the specified outputstreamstatic voidwriteAsNumpy(INDArray arr, File file)static voidwriteAsNumpy(INDArray arr, OutputStream writeTo)Writes an array to an output streamstatic voidwriteTxt(INDArray write, String filePath)Write NDArray to a text filestatic voidwriteTxt(INDArray write, String filePath, int precision)Deprecated.Defaults to scientific notation with 18 digits after the decimal UsewriteTxt(INDArray, String)static voidwriteTxt(INDArray write, String filePath, String split)Deprecated.custom col and higher dimension separators are no longer supported; uses "," UsewriteTxt(INDArray, String)static voidwriteTxt(INDArray write, String filePath, String split, int precision)Deprecated.Precision is no longer used.static INDArrayzeros(@lombok.NonNull int... shape)Create an ndarray of zerosstatic INDArrayzeros(@lombok.NonNull long... shape)Create an ndarray of zerosstatic INDArrayzeros(int[] shape, char order)Create an ndarray of zerosstatic INDArrayzeros(int[] shape, int[] stride)static INDArrayzeros(int[] shape, int[] stride, long offset)static INDArrayzeros(int[] shape, DataType dataType)static INDArrayzeros(int columns, char order)Create a 1D float array in soecified order initialized with zero.static INDArrayzeros(int rows, int columns, char ordering)Create a 2D array initialized with zeros.static INDArrayzeros(int rows, int columns, int[] stride)See {@link @see #create(int, int, int[], char)}static INDArrayzeros(int rows, int columns, int[] stride, long offset)static INDArrayzeros(long[] shape, char order)static INDArrayzeros(DataType dataType, @lombok.NonNull long... shape)Creates an array with the specified data tyoe and shape initialized with zero.static INDArrayzerosLike(INDArray arr)Empty like
-
-
-
Field Detail
-
bitwise
public static final NDBitwise bitwise
Bitwise namespace - operations related to bitwise manipulation of arrays
-
linalg
public static final NDLinalg linalg
Bitwise namespace - operations related to bitwise manipulation of arrays
-
math
public static final NDMath math
Math namespace - general mathematical operations
-
random
public static final NDRandom random
Random namespace - (pseudo) random number generation methods
-
nn
public static final NDNN nn
Neural network namespace - operations related to neural networks
-
loss
public static final NDLoss loss
Loss function namespace - operations related to loss functions.
-
cnn
public static final NDCNN cnn
Convolutional network namespace - operations related to convolutional neural networks
-
rnn
public static final NDRNN rnn
Recurrent neural network namespace - operations related to recurrent neural networks
-
image
public static final NDImage image
Image namespace - operations related to images
-
DTYPE
@Deprecated public static final String DTYPE
Deprecated.- See Also:
- Constant Field Values
-
NATIVE_OPS
public static final String NATIVE_OPS
- See Also:
- Constant Field Values
-
DISTRIBUTION
public static final String DISTRIBUTION
- See Also:
- Constant Field Values
-
LOG_INIT_ENV_PROPERTY
@Deprecated public static final String LOG_INIT_ENV_PROPERTY
Deprecated.- See Also:
- Constant Field Values
-
dtype
protected static DataType dtype
-
alloc
public static DataBuffer.AllocationMode alloc
-
EPS_THRESHOLD
public static double EPS_THRESHOLD
-
compressDebug
public static boolean compressDebug
-
preventUnpack
public static volatile boolean preventUnpack
-
backend
public static Nd4jBackend backend
-
randomFactory
public static RandomFactory randomFactory
-
INSTANCE
protected static NDArrayFactory INSTANCE
-
props
protected static Properties props
-
-
Method Detail
-
bitwise
public static NDBitwise bitwise()
Bitwise namespace - operations related to bitwise manipulation of arrays
-
math
public static NDMath math()
Math namespace - general mathematical operations
-
linalg
public static NDLinalg linalg()
Linalg namespace - operations related to linear algebra (lapack operations)
-
random
public static NDRandom random()
Random namespace - (pseudo) random number generation methods
-
nn
public static NDNN nn()
Neural network namespace - operations related to neural networks
-
loss
public static NDLoss loss()
Loss function namespace - operations related to loss functions.
-
cnn
public static NDCNN cnn()
Convolutional network namespace - operations related to convolutional neural networks
-
rnn
public static NDRNN rnn()
Recurrent neural network namespace - operations related to recurrent neural networks
-
image
public static NDImage image()
Image namespace - operations related to images
-
pad
public static INDArray pad(@NonNull @NonNull INDArray toPad, @NonNull @lombok.NonNull int[][] padWidth)
Seepad(INDArray, INDArray). Uses 0 padding.
-
pad
public static INDArray pad(@NonNull @NonNull INDArray toPad, @NonNull @lombok.NonNull int... padWidth)
Seepad(INDArray, INDArray). Uses 0 padding, and uses padWidth for all dimensions.
-
pad
public static INDArray pad(INDArray toPad, INDArray padding)
Seepad(INDArray, INDArray, Mode, double)with zero padding (zeros for padValue).
-
pad
public static INDArray pad(@NonNull @NonNull INDArray toPad, @NonNull @lombok.NonNull int[][] padWidth, @NonNull Pad.Mode padMode, double padValue)
-
pad
public static INDArray pad(@NonNull @NonNull INDArray toPad, @NonNull @lombok.NonNull int[] padWidth, @NonNull Pad.Mode padMode, double padValue)
Seepad(INDArray, INDArray, Mode, double), uses padWidth for all dimensions.
-
pad
public static INDArray pad(@NonNull @NonNull INDArray toPad, @NonNull @NonNull INDArray padWidth, @NonNull Pad.Mode padMode, double padValue)
Pad the given ndarray to the size along each dimension.- Parameters:
toPad- the ndarray to padpadWidth- the width to pad along each dimensionpadMode- the mode to pad inpadValue- the value used during padding. Only used when padMode isPad.Mode.CONSTANT.- Returns:
- the padded ndarray based on the specified mode
-
append
public static INDArray append(INDArray arr, int padAmount, double val, int axis)
Append the given array with the specified value size along a particular axis. The prepend method has the same signature and prepends the given array.- Parameters:
arr- the array to append topadAmount- the pad amount of the array to be returnedval- the value to appendaxis- the axis to append to- Returns:
- the newly created array
-
prepend
public static INDArray prepend(INDArray arr, int padAmount, double val, int axis)
Seeappend(INDArray, int, double, int). This function calls the implementation with appendFlag = false to prepend.
-
expandDims
public static INDArray expandDims(INDArray input, int dimension)
Expand the array dimensions. This is equivalent to adding a new axis dimension- Parameters:
input- the input arraydimension- the dimension to add the new axis at- Returns:
- the array with the new axis dimension
-
squeeze
public static INDArray squeeze(INDArray input, int dimension)
Squeeze : removes a dimension of size 1- Parameters:
input- the input arraydimension- the dimension to remove- Returns:
- the array with dimension removed
-
allowsSpecifyOrdering
public static boolean allowsSpecifyOrdering()
Backend specific: Returns whether specifying the order for the blas impl is allowed (cblas)- Returns:
- true if the blas impl can support specifying array order
-
shuffle
public static void shuffle(INDArray toShuffle, Random random, @NonNull @lombok.NonNull int... dimension)
In place shuffle of an ndarray along a specified set of dimensions- Parameters:
toShuffle- the ndarray to shufflerandom- the random to usedimension- the dimension to do the shuffle
-
shuffle
public static void shuffle(INDArray toShuffle, @NonNull @lombok.NonNull int... dimension)
In place shuffle of an ndarray along a specified set of dimensions- Parameters:
toShuffle- the ndarray to shuffledimension- the dimension to do the shuffle
-
shuffle
public static void shuffle(Collection<INDArray> toShuffle, @NonNull @lombok.NonNull int... dimension)
Symmetric in place shuffle of an ndarray along a specified set of dimensions- Parameters:
toShuffle- the ndarray to shuffledimension- the dimension to do the shuffle
-
shuffle
public static void shuffle(Collection<INDArray> toShuffle, Random rnd, @NonNull @lombok.NonNull int... dimension)
Symmetric in place shuffle of an ndarray along a specified set of dimensions- Parameters:
toShuffle- the ndarray to shuffledimension- the dimension to do the shuffle
-
shuffle
public static void shuffle(List<INDArray> toShuffle, Random rnd, List<int[]> dimensions)
Symmetric in place shuffle of an ndarray along a variable dimensions- Parameters:
toShuffle- the ndarray to shuffledimensions- the dimension to do the shuffle. Please note - order matters here.
-
getDistributions
public static DistributionFactory getDistributions()
Get the primary distributions factory- Returns:
- the primary distributions
-
getRandom
public static Random getRandom()
Get the current random generator- Returns:
- the current random generator
-
getRandomFactory
public static RandomFactory getRandomFactory()
Get the RandomFactory instance- Returns:
- the RandomFactory instance
-
getConvolution
public static ConvolutionInstance getConvolution()
Get the convolution singleton- Returns:
- the convolution singleton
-
setConvolution
public static void setConvolution(ConvolutionInstance convolutionInstance)
Set a convolution instance- Parameters:
convolutionInstance- the new convolution instance
-
shape
public static long[] shape(INDArray arr)
Returns the shape of the ndarray- Parameters:
arr- the array to get the shape of- Returns:
- the shape of tihs ndarray
-
create
public static INDArray create(int[] sliceShape, float[]... arrays)
Create an ndarray based on the given data- Parameters:
sliceShape- the shape of each slicearrays- the arrays of data to create- Returns:
- the ndarray of the specified shape where number of slices is equal to array length and each slice is the specified shape
-
create
public static INDArray create(LongShapeDescriptor descriptor)
Seecreate(LongShapeDescriptor, boolean)with initialize set to true.
-
create
public static INDArray create(LongShapeDescriptor descriptor, boolean initialize)
Create an ndarray based on the given description,- Parameters:
descriptor- object with data for array creation.initialize- true/false creates initialized/uninitialized array.- Returns:
- the ndarray of the specified description.
-
create
public static INDArray create(int[] sliceShape, double[]... arrays)
-
getEnvironment
public static Environment getEnvironment()
Get the backend Environment instance- Returns:
- The backend Environment instance
-
getExecutioner
public static OpExecutioner getExecutioner()
Get the operation executioner instance.- Returns:
- the operation executioner instance.
-
getDataBufferFactory
public static DataBufferFactory getDataBufferFactory()
Get the data buffer factory instance.- Returns:
- the data buffer factory instance.
-
rollAxis
public static INDArray rollAxis(INDArray a, int axis)
Roll the specified axis backwards, until it lies in a given position. Starting ends up being zero. See numpy's rollaxis- Parameters:
a- the array to rollaxis- the axis to roll backwards- Returns:
- the rolled ndarray
-
argMax
public static INDArray argMax(INDArray arr, @NonNull @lombok.NonNull int... dimension)
Get the maximum values for a dimension.- Parameters:
arr- input array.dimension- the dimension along which to get the maximum- Returns:
- array of maximum values.
-
argMin
public static INDArray argMin(INDArray arr, @NonNull @lombok.NonNull int... dimension)
SeeargMax(INDArray, int...)but return minimum values.
-
rollAxis
public static INDArray rollAxis(INDArray a, int axis, int start)
Roll the specified axis backwards, until it lies in a given position. See numpy's rollaxis- Parameters:
a- the array to rollaxis- the axis to roll backwardsstart- the starting point- Returns:
- the rolled ndarray
-
tensorMmul
public static INDArray tensorMmul(INDArray a, INDArray b, INDArray result, int[][] axes)
Tensor matrix multiplication. Both tensors must be the same rank- Parameters:
a- the left tensorb- the right tensorresult- the result arrayaxes- the axes for each array to do matrix multiply along- Returns:
- the result array
-
tensorMmul
public static INDArray tensorMmul(INDArray a, INDArray b, int[][] axes)
Tensor matrix multiplication. Both tensors must be the same rank- Parameters:
a- the left tensorb- the right tensoraxes- the axes for each array to do matrix multiply along- Returns:
- the multiplication result.
-
gemm
public static INDArray gemm(INDArray a, INDArray b, boolean transposeA, boolean transposeB)
matrix multiply: implements op(a)*op(b) where op(x) means transpose x (or not) depending on setting of arguments transposea and transposeb.
so gemm(a,b,false,false) == a.mmul(b), gemm(a,b,true,false) == a.transpose().mmul(b) etc.- Parameters:
a- first matrixb- second matrixtransposeA- if true: transpose matrix a before mmultransposeB- if true: transpose matrix b before mmul- Returns:
- result
-
gemm
public static INDArray gemm(INDArray a, INDArray b, INDArray c, boolean transposeA, boolean transposeB, double alpha, double beta)
Matrix multiply: Implements c = alpha*op(a)*op(b) + beta*c where op(X) means transpose X (or not) depending on setting of arguments transposeA and transposeB.
Note that matrix c MUST be fortran order, have zero offset and have c.data().length == c.length(). i.e., the result array must not be a view. An exception will be thrown otherwise.
(Note: some views are allowed, if and only if they have f order and are contiguous in the buffer other than an offset. Put another way, they must be f order and have strides identical to a non-view/default array of the same shape)
Don't use this unless you know about level 3 blas and NDArray storage orders.- Parameters:
a- First matrixb- Second matrixc- result matrix. Used in calculation (assuming beta != 0) and result is stored in this. f order, and not a view onlytransposeA- if true: transpose matrix a before mmultransposeB- if true: transpose matrix b before mmul- Returns:
- result, i.e., matrix c is returned for convenience
-
matmul
public static INDArray matmul(INDArray a, INDArray b, INDArray result, boolean transposeA, boolean transposeB, boolean transposeResult)
Matrix multiplication/dot product Depending on inputs dimensionality output result might be different. matrix x matrix = BLAS gemm vector x matrix = BLAS gemm vector x vector = BLAS dot vector x scalar = element-wise mul scalar x vector = element-wise mul tensor x tensor = matrix multiplication using the last two dimensions Transpose operations only available where applicable. In the tensor x tensor case it will be applied only to the last two dimensions.- Parameters:
a- First tensorb- Second tensorresult- result matrix.transposeA- if true: transpose matrix a before mmultransposeB- if true: transpose matrix b before mmultransposeResult- if true: result matrix will be transposed- Returns:
- result, i.e., result matrix is returned for convenience
-
matmul
public static INDArray matmul(INDArray a, INDArray b, INDArray result)
Matrix multiplication/dot product.
Seematmul(INDArray, INDArray, INDArray, boolean, boolean, boolean)
-
matmul
public static INDArray matmul(INDArray a, INDArray b, boolean transposeA, boolean transposeB, boolean transposeResult)
Matrix multiplication/dot product.
Seematmul(INDArray, INDArray, INDArray, boolean, boolean, boolean)
-
matmul
public static INDArray matmul(INDArray a, INDArray b)
Matrix multiplication/dot product Seematmul(INDArray, INDArray, INDArray, boolean, boolean, boolean)
-
factory
public static NDArrayFactory factory()
The factory used for creating ndarrays- Returns:
- the factory instance used for creating ndarrays
-
cumsum
public static INDArray cumsum(INDArray compute)
SeeINDArray.cumsum(int)with Integer.MAX_VALUE for full array reduction.- Returns:
- scalar ndarray.
-
max
public static INDArray max(INDArray compute)
SeeINDArray.max(int...)with Integer.MAX_VALUE for full array reduction.
-
min
public static INDArray min(INDArray compute)
SeeINDArray.min(int...)with Integer.MAX_VALUE for full array reduction.
-
prod
public static INDArray prod(INDArray compute)
SeeINDArray.prod(int...)with Integer.MAX_VALUE for full array reduction.
-
normmax
public static INDArray normmax(INDArray compute)
SeeINDArray.normmax(int...)with Integer.MAX_VALUE for full array reduction.
-
norm2
public static INDArray norm2(INDArray compute)
SeeINDArray.norm2(int...)with Integer.MAX_VALUE for full array reduction.
-
norm1
public static INDArray norm1(INDArray compute)
SeeINDArray.norm1(int...)with Integer.MAX_VALUE for full array reduction.
-
std
public static INDArray std(INDArray compute)
SeeINDArray.std(int...)with Integer.MAX_VALUE for full array reduction.
-
var
public static INDArray var(INDArray compute)
SeeINDArray.var(int...)with Integer.MAX_VALUE for full array reduction.
-
sum
public static INDArray sum(INDArray compute)
SeeINDArray.sum(int...)with Integer.MAX_VALUE for full array reduction.
-
mean
public static INDArray mean(INDArray compute)
SeeINDArray.mean(int...)with Integer.MAX_VALUE for full array reduction.
-
cumsum
public static INDArray cumsum(INDArray compute, int dimension)
SeeINDArray.cumsum(int)with Integer.MAX_VALUE for full array reduction.
-
max
public static INDArray max(INDArray compute, int dimension)
SeeINDArray.max(int...)with Integer.MAX_VALUE for full array reduction.
-
min
public static INDArray min(INDArray compute, int dimension)
SeeINDArray.min(int...)with Integer.MAX_VALUE for full array reduction.
-
prod
public static INDArray prod(INDArray compute, int dimension)
SeeINDArray.prod(int...)with Integer.MAX_VALUE for full array reduction.
-
normmax
public static INDArray normmax(INDArray compute, int dimension)
SeeINDArray.normmax(int...)with Integer.MAX_VALUE for full array reduction.
-
norm2
public static INDArray norm2(INDArray compute, int dimension)
SeeINDArray.norm2(int...)with Integer.MAX_VALUE for full array reduction.
-
norm1
public static INDArray norm1(INDArray compute, int dimension)
SeeINDArray.norm1(int...)with Integer.MAX_VALUE for full array reduction.
-
std
public static INDArray std(INDArray compute, int dimension)
SeeINDArray.std(int...)with Integer.MAX_VALUE for full array reduction.
-
var
public static INDArray var(INDArray compute, int dimension)
SeeINDArray.var(int...)with Integer.MAX_VALUE for full array reduction.
-
sum
public static INDArray sum(INDArray compute, int dimension)
SeeINDArray.sum(int...)with Integer.MAX_VALUE for full array reduction.
-
mean
public static INDArray mean(INDArray compute, int dimension)
SeeINDArray.mean(int...)with Integer.MAX_VALUE for full array reduction.
-
createBuffer
public static DataBuffer createBuffer(DataBuffer underlyingBuffer, long offset, long length)
Create a view of a data buffer Leverages the underlying storage of the buffer with a new view- Parameters:
underlyingBuffer- the underlying bufferoffset- the offset for the view- Returns:
- the new view of the data buffer
-
createBuffer
public static DataBuffer createBuffer(int[] shape, DataType type, long offset)
Create a buffer equal of length prod(shape)- Parameters:
shape- the shape of the buffer to createtype- the opType to create- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(ByteBuffer buffer, DataType type, int length, long offset)
Creates a buffer of the specified opType and length with the given byte buffer. This will wrap the buffer as a reference (no copy) if the allocation opType is the same.- Parameters:
buffer- the buffer to create fromtype- the opType of buffer to createlength- the length of the buffer- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(byte[] data, int length, long offset)
Create a buffer based on the data opType- Parameters:
data- the data to create the buffer with- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(int length, long offset)
Creates a buffer of the specified length based on the data opType- Parameters:
length- the length of te buffer- Returns:
- the buffer to create
-
createBuffer
public static DataBuffer createBuffer(@NonNull @NonNull org.bytedeco.javacpp.Pointer pointer, long length, @NonNull @NonNull DataType dataType)
Creates a buffer of the specified type and length with the given pointer.- Parameters:
pointer- pointer to data to create from.length- the length of the bufferdataType- the opType of buffer to create,- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(@NonNull @NonNull org.bytedeco.javacpp.Pointer pointer, @NonNull @NonNull org.bytedeco.javacpp.Pointer devicePointer, long length, @NonNull @NonNull DataType dataType)
Creates a buffer of the specified type and length with the given pointer at the specified device. (This method is relevant only for a CUDA backend).- Parameters:
pointer- pointer to data to create from.devicePointer- pointer to device to create in (only implemented in the CUDA backend)length- the length of the bufferdataType- the opType of buffer to create,- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(float[] data, long offset)
Create a buffer based on the data opType- Parameters:
data- the data to create the buffer with- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(double[] data, long offset)
Create a buffer based on the data opType- Parameters:
data- the data to create the buffer with- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(@NonNull @lombok.NonNull int[] shape, @NonNull @NonNull DataType type)
Create a buffer equal of length prod(shape)- Parameters:
shape- the shape of the buffer to createtype- the opType to create- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(@NonNull @lombok.NonNull long[] shape, @NonNull @NonNull DataType type)
-
createBufferDetached
public static DataBuffer createBufferDetached(int[] shape, DataType type)
Create a buffer equal of length prod(shape). The buffer is 'detached': Not in any memory workspace even if a workspace is currently open.- Parameters:
shape- the shape of the buffer to createtype- the opType to create- Returns:
- the created buffer.
-
createBufferDetached
public static DataBuffer createBufferDetached(long[] shape, DataType type)
-
createBuffer
public static DataBuffer createBuffer(ByteBuffer buffer, DataType type, int length)
Creates a buffer of the specified opType and length with the given byte buffer. This will wrap the buffer as a reference (no copy) if the allocation opType is the same.- Parameters:
buffer- the buffer to create fromtype- the opType of buffer to createlength- the length of the buffer- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(int[] data)
Create a buffer equal of length prod(shape)- Parameters:
data- the shape of the buffer to create- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(long[] data)
Create a buffer equal of length prod(shape)- Parameters:
data- the shape of the buffer to create- Returns:
- the created buffer
-
createBufferDetached
public static DataBuffer createBufferDetached(int[] data)
Create a buffer equal of length prod(shape). This method is NOT affected by workspaces- Parameters:
data- the shape of the buffer to create- Returns:
- the created buffer
-
createBufferDetached
public static DataBuffer createBufferDetached(long[] data)
Create a buffer equal of length prod(shape). This method is NOT affected by workspaces- Parameters:
data- the shape of the buffer to create- Returns:
- the created buffer
-
createBuffer
public static DataBuffer createBuffer(long length)
Creates a buffer of the specified length based on the data opType- Parameters:
length- the length of te buffer- Returns:
- the buffer to create
-
createBuffer
public static DataBuffer createBuffer(org.bytedeco.javacpp.Pointer pointer, DataType type, long length, org.bytedeco.javacpp.indexer.Indexer indexer)
Create a data buffer based on a pointer with the given opType and length- Parameters:
pointer- the pointer to create the buffer fortype- the opType of pointerlength- the length of the bufferindexer- the indexer to use- Returns:
- the data buffer based on the given parameters
-
createBuffer
public static DataBuffer createBuffer(long length, boolean initialize)
-
createBuffer
public static DataBuffer createBuffer(DataType dataType, long length, boolean initialize)
Create a data buffer based on datatype.- Parameters:
dataType- the type of buffer to createlength- the length of the bufferinitialize- flag to leave the underlying memory (false) or initialize with zero (true).- Returns:
- the created buffer.
-
createBuffer
public static DataBuffer createBuffer(DataType dataType, long length, boolean initialize, MemoryWorkspace workspace)
Create a data buffer based on datatype, workspace.- Parameters:
dataType- the type of buffer to createlength- the length of the bufferinitialize- flag to leave the underlying memory (false) or initialize with zero (true).workspace- workspace to use for buffer creation.- Returns:
- the created buffer.
-
createBuffer
public static DataBuffer createBuffer(float[] data)
Create a buffer based on the data opType- Parameters:
data- the data to create the buffer with- Returns:
- the created buffer
-
createBufferDetached
public static DataBuffer createBufferDetached(float[] data)
Create a buffer based on underlying array.- Parameters:
data- data to create the buffer with- Returns:
- the created buffer
-
createBufferDetached
public static DataBuffer createBufferDetached(double[] data)
-
createBuffer
public static DataBuffer createBuffer(double[] data)
-
createTypedBuffer
public static DataBuffer createTypedBuffer(double[] data, DataType dataType)
Create a buffer based on the data of the underlying java array with the specified type..- Parameters:
data- underlying java arraydataType- specified type.- Returns:
- created buffer,
-
createTypedBuffer
public static DataBuffer createTypedBuffer(float[] data, DataType dataType)
-
createTypedBuffer
public static DataBuffer createTypedBuffer(int[] data, DataType dataType)
-
createTypedBuffer
public static DataBuffer createTypedBuffer(long[] data, DataType dataType)
-
createTypedBuffer
public static DataBuffer createTypedBuffer(short[] data, DataType dataType)
-
createTypedBuffer
public static DataBuffer createTypedBuffer(byte[] data, DataType dataType)
-
createTypedBuffer
public static DataBuffer createTypedBuffer(boolean[] data, DataType dataType)
-
createTypedBuffer
public static DataBuffer createTypedBuffer(double[] data, DataType dataType, MemoryWorkspace workspace)
Create a buffer based on the data of the underlying java array, specified type and workspace- Parameters:
data- underlying java arraydataType- specified type.workspace- specified workspace.- Returns:
- created buffer,
-
createTypedBuffer
public static DataBuffer createTypedBuffer(float[] data, DataType dataType, MemoryWorkspace workspace)
-
createTypedBufferDetached
public static DataBuffer createTypedBufferDetached(double[] data, DataType dataType)
Create am uninitialized buffer based on the data of the underlying java array and specified type.- Parameters:
data- underlying java arraydataType- specified type.- Returns:
- the created buffer.
-
createTypedBufferDetached
public static DataBuffer createTypedBufferDetached(float[] data, DataType dataType)
-
createTypedBufferDetached
public static DataBuffer createTypedBufferDetached(int[] data, DataType dataType)
-
createTypedBufferDetached
public static DataBuffer createTypedBufferDetached(long[] data, DataType dataType)
-
createTypedBufferDetached
public static DataBuffer createTypedBufferDetached(short[] data, DataType dataType)
-
createTypedBufferDetached
public static DataBuffer createTypedBufferDetached(byte[] data, DataType dataType)
-
createTypedBufferDetached
public static DataBuffer createTypedBufferDetached(boolean[] data, DataType dataType)
-
setFactory
public static void setFactory(NDArrayFactory factory)
Set the factory instance for INDArray creation.- Parameters:
factory- new INDArray factory
-
order
public static Character order()
Returns the ordering of the ndarrays- Returns:
- the ordering of the ndarrays
-
dataType
public static DataType dataType()
Returns the data opType used for the runtime- Returns:
- the datatype used for the runtime
-
setDataType
@Deprecated public static void setDataType(@NonNull @NonNull DataType dtype)
Deprecated.usesetDefaultDataTypes(DataType, DataType). Equivalent tosetDefaultDataTypes(dtype, (dtype.isFPType() ? dtype : defaultFloatingPointType()))DEPRECATED - usesetDefaultDataTypes(DataType, DataType)This method sets dataType for the current JVM.- Parameters:
dtype- Data type to set
-
setDefaultDataTypes
public static void setDefaultDataTypes(@NonNull @NonNull DataType defaultType, @NonNull @NonNull DataType defaultFloatingPointType)Set the default data types.
The default data types are used for array creation methods where no data type is specified.
When the user explicitly provides a datatype (such as in Nd4j.ones(DataType.FLOAT, 1, 10)) these default values will not be used.
defaultType: used in methods such as Nd4j.ones(1,10) and Nd4j.zeros(10).
defaultFloatingPointType: used internally where a floating point array needs to be created, but no datatype is specified. defaultFloatingPointType must be one of DOUBLE, FLOAT or HALF- Parameters:
defaultType- Default datatype for new arrays (used when no type is specified).defaultFloatingPointType- Default datatype for new floating point arrays (used when no type is specified. Must be one of DOUBLE, FLOAT or HALF
-
getBackend
public static Nd4jBackend getBackend()
Retrieve the Nd4J backend.- Returns:
- the Nd4J backend.
-
getBlasWrapper
public static BlasWrapper getBlasWrapper()
Retrieve the BLAS wrapper.- Returns:
- the BLAS wrapper.
-
sortWithIndices
public static INDArray[] sortWithIndices(INDArray ndarray, int dimension, boolean ascending)
Sort an ndarray along a particular dimension.
Note that the input array is modified in-place.- Parameters:
ndarray- the ndarray to sortdimension- the dimension to sort- Returns:
- the indices and the sorted ndarray (the original array, modified in-place)
-
sort
public static INDArray sort(INDArray ndarray, boolean ascending)
Sort all elements of an array. sorts all elements of an array. For multi dimansional arrays the result depends on the array ordering] Nd4j.factory().setOrder('f'); INDArray x = Nd4j.arange(4).reshape(2,2); Nd4j.sort(x, true); gives: [[ 0, 2.0000], [ 1.0000, 3.0000]] The same ode with .setOrder('c') [[ 0, 1.0000], [ 2.0000, 3.0000]]- Parameters:
ndarray- array to sortascending- true for ascending, false for descending- Returns:
- the sorted ndarray
-
sort
public static INDArray sort(INDArray ndarray, int dimension, boolean ascending)
Sort an ndarray along a particular dimension
Note that the input array is modified in-place.- Parameters:
ndarray- the ndarray to sortdimension- the dimension to sort- Returns:
- the sorted ndarray
-
sortRows
public static INDArray sortRows(INDArray in, int colIdx, boolean ascending)
Sort (shuffle) the rows of a 2d array according to the value at a specified column. Other than the order of the rows, each row is unmodified. Copy operation: original INDArray is unmodified
So if sorting the following on values of column 2 (ascending):
[a b 2]
[c d 0]
[e f -3]
Then output is
[e f -3]
[c d 0]
[a b 2]- Parameters:
in- 2d array to sortcolIdx- The column to sort onascending- true if smallest-to-largest; false if largest-to-smallest- Returns:
- the sorted ndarray
-
sortColumns
public static INDArray sortColumns(INDArray in, int rowIdx, boolean ascending)
Sort (shuffle) the columns of a 2d array according to the value at a specified row. Other than the order of the columns, each column is unmodified. Copy operation: original INDArray is unmodified
So if sorting the following on values of row 1 (ascending):
[a b c]
[1 -1 0]
[d e f]
Then output is
[b c a]
[-1 0 1]
[e f d]- Parameters:
in- 2d array to sortrowIdx- The row to sort onascending- true if smallest-to-largest; false if largest-to-smallest- Returns:
- the sorted array.
-
repeat
public static INDArray repeat(INDArray n, int num)
Create an n x (shape) ndarray where the ndarray is repeated num times- Parameters:
n- the ndarray to replicatenum- the number of copies to repeat- Returns:
- the repeated ndarray
-
linspace
public static INDArray linspace(@NonNull @NonNull DataType dtype, long lower, long num, long step)
Generate a linearly spaced vector- Parameters:
lower- upper boundnum- number of items in returned vectorstep- the step (incompatible with upper)- Returns:
- the linearly spaced vector
-
linspace
public static INDArray linspace(long lower, long upper, long num)
Generate a linearly spaced vector with default data type- Parameters:
lower- lower boundupper- upper boundnum- number of items in returned vector- Returns:
- the linearly spaced vector
-
linspace
public static INDArray linspace(long lower, long upper, long num, @NonNull @NonNull DataType dtype)
Generate a linearly spaced vector- Parameters:
lower- lower boundupper- upper boundnum- number of items in returned vector- Returns:
- the linearly spaced vector
-
linspace
public static INDArray linspace(@NonNull @NonNull DataType dataType, double lower, double step, long num)
Generate a linearly spaced 1d vector of the specified datatype- Parameters:
lower- lower boundstep- step between itemsnum- number of resulting items- Returns:
- the linearly spaced vector
-
linspace
public static INDArray linspace(double lower, double upper, long num, @NonNull @NonNull DataType dataType)
Generate a linearly spaced 1d vector of the specified datatype- Parameters:
lower- lower boundupper- upper boundnum- number of resulting items- Returns:
- the linearly spaced vector
-
meshgrid
public static INDArray[] meshgrid(@NonNull @NonNull INDArray x, @NonNull @NonNull INDArray y)
Meshgrid op. Returns a pair of arrays where values are broadcast on a 2d grid.
For example, if x = [1,2,3,4] and y = [5,6,7], then:
out[0] =
[1,2,3,4]
[1,2,3,4]
[1,2,3,4]
out[1] =
[5,5,5,5]
[6,6,6,6]
[7,7,7,7]
- Parameters:
x- X array inputy- Y array input- Returns:
- INDArray[] of length 2, shape [y.length, x.length]
-
toFlattened
public static INDArray toFlattened(Collection<INDArray> matrices)
Create a long row vector of all of the given ndarrays- Parameters:
matrices- the matrices to create the flattened ndarray for- Returns:
- the flattened representation of these ndarrays
-
toFlattened
public static INDArray toFlattened(char order, Collection<INDArray> matrices)
Create a long row vector of all of the given ndarrays- Parameters:
order- the order in which to flatten the matricesmatrices- the matrices to create the flattened ndarray for- Returns:
- the flattened representation of these ndarrays
-
toFlattened
public static INDArray toFlattened(@NonNull @NonNull INDArray... matrices)
Create a long row vector of all of the given ndarrays- Parameters:
matrices- the matrices to create the flattened ndarray for- Returns:
- the flattened representation of these ndarrays
-
toFlattened
public static INDArray toFlattened(char order, @NonNull @NonNull INDArray... matrices)
Create a long row vector of all of the given ndarrays/- Parameters:
order- order in which to flatten ndarraysmatrices- the matrices to create the flattened ndarray for- Returns:
- the flattened representation of these ndarrays
-
eye
public static INDArray eye(long n)
Create the identity ndarray- Parameters:
n- the number for the identity- Returns:
- the identity array
-
rot90
public static void rot90(INDArray toRotate)
Rotate a matrix 90 degrees- Parameters:
toRotate- the matrix to rotate
-
writeTxt
public static void writeTxt(INDArray write, String filePath, String split, int precision)
Deprecated.Precision is no longer used. Split is no longer used. Defaults to scientific notation with 18 digits after the decimal UsewriteTxt(INDArray, String)Write NDArray to a text file- Parameters:
filePath- path to write tosplit- the split separator, defaults to ","precision- digits after the decimal point
-
writeTxt
public static void writeTxt(INDArray write, String filePath, int precision)
Deprecated.Defaults to scientific notation with 18 digits after the decimal UsewriteTxt(INDArray, String)Write NDArray to a text file- Parameters:
write- array to writefilePath- path to write toprecision- Precision is no longer used.
-
writeTxt
public static void writeTxt(INDArray write, String filePath, String split)
Deprecated.custom col and higher dimension separators are no longer supported; uses "," UsewriteTxt(INDArray, String)Write NDArray to a text file- Parameters:
write- array to writefilePath- path to write tosplit- the split separator, defaults to ","
-
writeTxt
public static void writeTxt(INDArray write, String filePath)
Write NDArray to a text file- Parameters:
write- Array to writefilePath- path to write to
-
write
public static void write(OutputStream writer, INDArray write) throws IOException
Y Write an ndarray to a writer- Parameters:
writer- the writer to write towrite- the ndarray to write- Throws:
IOException
-
toByteArray
public static byte[] toByteArray(@NonNull @NonNull INDArray arr) throws IOExceptionConvert an ndarray to a byte array- Parameters:
arr- the array to convert- Returns:
- the converted byte array
- Throws:
IOException
-
fromByteArray
public static INDArray fromByteArray(@NonNull @lombok.NonNull byte[] arr)
Read an ndarray from a byte array- Parameters:
arr- the array to read from- Returns:
- the deserialized ndarray
-
readNumpy
public static INDArray readNumpy(@NonNull @NonNull InputStream filePath, @NonNull @NonNull String split) throws IOException
Read line via input streams- Parameters:
filePath- the input stream ndarraysplit- the split separator- Returns:
- the read txt method
- Throws:
IOException
-
readNumpy
public static INDArray readNumpy(@NonNull @NonNull DataType dataType, @NonNull @NonNull InputStream filePath, @NonNull @NonNull String split, @NonNull @NonNull Charset charset) throws IOException
Read array from input stream.- Parameters:
dataType- datatype of arrayfilePath- the input streamsplit- the split separatorcharset- the charset- Returns:
- the deserialized array.
- Throws:
IOException
-
readNumpy
public static INDArray readNumpy(String filePath, String split) throws IOException
Read line via input streams- Parameters:
filePath- the input stream ndarraysplit- the split separator- Returns:
- the read txt method
- Throws:
IOException
-
readNumpy
public static INDArray readNumpy(DataType dataType, String filePath, String split) throws IOException
Read array via input stream. SeereadNumpy(DataType, InputStream, String , Charset)using standard UTF-8 encoding- Throws:
IOException
-
readNumpy
public static INDArray readNumpy(String filePath) throws IOException
Read line via input streams- Parameters:
filePath- the input stream ndarray- Returns:
- the read txt method
- Throws:
IOException
-
readNumpy
public static INDArray readNumpy(DataType dataType, String filePath) throws IOException
Read array.
SeereadNumpy(DataType, InputStream, String , Charset)with default split and UTF-8 encoding.- Throws:
IOException
-
read
public static INDArray read(InputStream reader)
Raad an ndarray from an input stream Seeread(DataInputStream)
-
readTxtString
@Deprecated public static INDArray readTxtString(InputStream ndarray)
Deprecated.To be removed in 1.0Read line via input streams- Parameters:
ndarray- the input stream ndarray- Returns:
- NDArray
-
readTxt
@Deprecated public static INDArray readTxt(String filePath)
Deprecated.to be removed in 1.0Read line via input streams- Parameters:
filePath- the input stream ndarray- Returns:
- NDArray
-
createArrayFromShapeBuffer
public static INDArray createArrayFromShapeBuffer(DataBuffer data, DataBuffer shapeInfo)
Create array based in data buffer and shape info,- Parameters:
data- Data buffer.shapeInfo- shape information.- Returns:
- new INDArray.
-
createArrayFromShapeBuffer
public static INDArray createArrayFromShapeBuffer(DataBuffer data, Pair<DataBuffer,long[]> shapeInfo)
Create array based in data buffer and shape info,- Parameters:
data- data buffer.shapeInfo- shape information.- Returns:
- new INDArray.
-
read
public static INDArray read(DataInputStream dis)
Read in an ndarray from a data input stream- Parameters:
dis- the data input stream to read from- Returns:
- the ndarray
-
write
public static void write(INDArray arr, DataOutputStream dataOutputStream) throws IOException
Write an ndarray to the specified outputstream- Parameters:
arr- the array to writedataOutputStream- the data output stream to write to- Throws:
IOException
-
saveBinary
public static void saveBinary(INDArray arr, File saveTo) throws IOException
Save an ndarray to the given file- Parameters:
arr- the array to savesaveTo- the file to save to- Throws:
IOException
-
readBinary
public static INDArray readBinary(File read) throws IOException
Read a binary ndarray from the given file- Parameters:
read- the nd array to read- Returns:
- the loaded ndarray
- Throws:
IOException
-
clearNans
public static void clearNans(INDArray arr)
Clear nans from an ndarray- Parameters:
arr- the array to clear
-
reverse
public static INDArray reverse(INDArray reverse)
Reverses the passed in matrix such that m[0] becomes m[m.length - 1] etc- Parameters:
reverse- the matrix to reverse- Returns:
- the reversed matrix
-
arange
public static INDArray arange(double begin, double end, double step)
Create a 1D array of evenly spaced values betweenbegin(inclusive) andend(exclusive) with a step size.- Parameters:
begin- the begin of the range (inclusive)end- the end of the range (exclusive)step- spacing between values. Default value is 1.- Returns:
- the 1D range vector
-
arange
public static INDArray arange(double begin, double end)
Create a 1D array of evenly spaced values betweenbegin(inclusive) andend(exclusive) with a step size of 1 Seearange(double, double, double)with step size 1.
-
arange
public static INDArray arange(double end)
Create a 1D array of evenly spaced values between 0 (inclusive) andend(exclusive) with a step size of 1 Seearange(double, double, double)with begin = 0 and step size 1.
-
copy
public static void copy(INDArray a, INDArray b)
Copy a to b- Parameters:
a- the origin matrixb- the destination matrix
-
diag
public static INDArray diag(INDArray x)
Creates a new matrix where the values of the given vector are the diagonal values of the matrix if a vector is passed in, if a matrix is returns the kth diagonal in the matrix- Parameters:
x- the diagonal values- Returns:
- new matrix
-
choice
public static INDArray choice(@NonNull @NonNull INDArray source, @NonNull @NonNull INDArray probs, @NonNull @NonNull INDArray target, @NonNull Random rng)
This method samples value from Source array to Target, with probabilites provided in Probs argument- Parameters:
source- source array.probs- array with probabilities.target- destination array.rng- Random number generator.- Returns:
- the destination (target) array.
-
choice
public static INDArray choice(INDArray source, INDArray probs, INDArray target)
This method samples value from Source array to Target,the default random number generator.
-
choice
public static INDArray choice(INDArray source, INDArray probs, int numSamples, @NonNull Random rng)
This method returns new INDArray instance, sampled from Source array with probabilities given in Probs.- Parameters:
numSamples- number of samples to take. (size of the new NDArray).- See Also:
choice(INDArray, INDArray, int, org.nd4j.linalg.api.rng.Random)
-
choice
public static INDArray choice(INDArray source, INDArray probs, int numSamples)
This method returns new INDArray instance, sampled from Source array with probabilities given in Probs using the default random number generator.
-
rand
public static INDArray rand(@NonNull @lombok.NonNull int... shape)
Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape- Parameters:
shape- the shape of the array- Returns:
- the random ndarray with the specified shape
-
rand
public static INDArray rand(@NonNull @lombok.NonNull long... shape)
Seerand(int[])
-
rand
public static INDArray rand(@NonNull @NonNull DataType dataType, @NonNull @lombok.NonNull long... shape)
Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape and data type- Parameters:
shape- the shape of the ndarray- Returns:
- the random ndarray with the specified shape
-
rand
public static INDArray rand(char order, @NonNull @lombok.NonNull int... shape)
Create a random ndarray with the given shape and array order Values are sampled from a uniform distribution over (0, 1)- Parameters:
order- the order of the ndarray to returnshape- the shape of the array- Returns:
- the random ndarray with the specified shape
-
rand
@Deprecated public static INDArray rand(@NonNull @NonNull DataType dataType, int[] shape, char order)
Deprecated.use {@link Nd4j#rand(DataType, char, long...))
-
rand
@Deprecated public static INDArray rand(@NonNull @NonNull DataType dataType, char order, @NonNull @lombok.NonNull int... shape)
Deprecated.
-
rand
public static INDArray rand(@NonNull @NonNull DataType dataType, char order, @NonNull @lombok.NonNull long... shape)
Create a random ndarray with the given shape, data type, and array order Values are sampled from a uniform distribution over (0, 1)- Parameters:
order- the order of the ndarray to returnshape- the shape of the ndarraydataType- the data type of the ndarray- Returns:
- the random ndarray with the specified shape
-
rand
public static INDArray rand(@NonNull @NonNull DataType dataType, @NonNull @lombok.NonNull int... shape)
Create a random ndarray with the given shape and data type Values are sampled from a uniform distribution over (0, 1)- Parameters:
shape- the shape of the ndarraydataType- the data type of the ndarray- Returns:
- the random ndarray with the specified shape
-
rand
public static INDArray rand(long seed, @NonNull @lombok.NonNull long... shape)
Create a random ndarray with values from a uniform distribution over (0, 1) with the given shape using given seed- Parameters:
shape- the shape of the arrayseed- the seed to use- Returns:
- the random ndarray with the specified shape
-
rand
@Deprecated public static INDArray rand(int[] shape, long seed)
Deprecated.
-
rand
@Deprecated public static INDArray rand(int[] shape, @NonNull Random rng)
Deprecated.
-
rand
public static INDArray rand(@NonNull Random rng, @NonNull @lombok.NonNull long... shape)
Create a random ndarray with the given shape using the given RandomGenerator- Parameters:
shape- the shape of the arrayrng- the random generator to use- Returns:
- the random ndarray with the specified shape
-
rand
@Deprecated public static INDArray rand(int[] shape, @NonNull @NonNull Distribution dist)
Deprecated.
-
rand
@Deprecated public static INDArray rand(long[] shape, @NonNull @NonNull Distribution dist)
Deprecated.
-
rand
public static INDArray rand(@NonNull @NonNull Distribution dist, @NonNull @lombok.NonNull long... shape)
Create a random ndarray with the given shape using the given rng- Parameters:
shape- the shape of the arraydist- distribution to use- Returns:
- the random ndarray with the specified shape
-
rand
public static INDArray rand(int rows, int columns, @NonNull Random rng)
Create a random ndarray with the given shape using the given rng- Parameters:
rows- the number of rows in the matrixcolumns- the number of columns in the matrixrng- the random generator to use- Returns:
- the random ndarray with the specified shape
-
rand
@Deprecated public static INDArray rand(int[] shape, double min, double max, @NonNull Random rng)
Deprecated.
-
rand
@Deprecated public static INDArray rand(long[] shape, double min, double max, @NonNull Random rng)
Deprecated.
-
rand
public static INDArray rand(double min, double max, @NonNull Random rng, @NonNull @lombok.NonNull long... shape)
Generates a random matrix between min and max- Parameters:
shape- the number of rows of the matrixmin- the minimum numbermax- the maximum numberrng- the rng to use- Returns:
- a random matrix of the specified shape and range
-
randn
public static INDArray randn(INDArray target)
Fill the given ndarray with random numbers drawn from a normal distribution- Parameters:
target- target array- Returns:
- the given target array
-
randn
public static INDArray randn(@NonNull @lombok.NonNull int[] shape)
Create a ndarray of the given shape with values from N(0,1)- Parameters:
shape- the shape of the array- Returns:
- new array with random values
-
randn
public static INDArray randn(@NonNull @NonNull DataType dataType, @NonNull @lombok.NonNull int[] shape)
Create a ndarray of the given shape and data type with values from N(0,1)- Parameters:
shape- the shape of the ndarray- Returns:
- new array with random values
-
randn
public static INDArray randn(@NonNull @NonNull DataType dataType, @NonNull @lombok.NonNull long... shape)
Create a ndarray of the given shape and data type with values from N(0,1)- Parameters:
dataType- datatype to use, must be a float type datatype.shape- shape for the new array.- Returns:
- new array with random values
-
randn
public static INDArray randn(@NonNull @lombok.NonNull long... shape)
Create a ndarray of the given shape with values from N(0,1). Defaults to FLOAT and c-order.- Parameters:
shape- shape for the new array.- Returns:
- new array with random values
-
randn
public static INDArray randn(char order, @NonNull @lombok.NonNull int... shape)
Random normal N(0,1) with the specified shape and array order- Parameters:
order- order of the output ndarrayshape- the shape of the array- Returns:
- new array with random values
-
randn
public static INDArray randn(char order, @NonNull @lombok.NonNull long... shape)
Random normal N(0,1) with the specified shape and array order- Parameters:
order- order of the output ndarrayshape- the shape of the array- Returns:
- new array with random values
-
randn
public static INDArray randn(@NonNull @NonNull DataType dataType, char order, @NonNull @lombok.NonNull long... shape)
Random normal N(0,1) with the specified shape and array order- Parameters:
order- order of the output ndarrayshape- the shape of the ndarraydataType- the data type of the ndarray
-
randn
@Deprecated public static INDArray randn(long seed, int[] shape)
Deprecated.
-
randn
public static INDArray randn(long seed, @NonNull @lombok.NonNull long[] shape)
Random normal N(0, 1) using the specified seed- Parameters:
shape- the shape of the array- Returns:
- new array with random values
-
randn
@Deprecated public static INDArray randn(int[] shape, @NonNull Random r)
Deprecated.
-
randn
@Deprecated public static INDArray randn(long[] shape, @NonNull Random r)
Deprecated.
-
randn
public static INDArray randn(@NonNull Random r, @NonNull @lombok.NonNull long... shape)
Random normal using the given rng- Parameters:
shape- the shape of the arrayr- the random generator to use- Returns:
- new array with random values
-
randn
public static INDArray randn(double mean, double stddev, INDArray target, @NonNull Random rng)
-
rand
public static INDArray rand(INDArray target)
Fill the given ndarray with random numbers drawn from a uniform distribution- Parameters:
target- target array- Returns:
- the given target array
-
rand
public static INDArray rand(INDArray target, long seed)
Fill the given ndarray with random numbers drawn from a uniform distribution- Parameters:
target- target arrayseed- the seed to use- Returns:
- the given target array
-
rand
public static INDArray rand(INDArray target, @NonNull Random rng)
Fill the given ndarray with random numbers drawn from a uniform distribution using the given RandomGenerator- Parameters:
target- target arrayrng- the random generator to use- Returns:
- the given target array
-
rand
public static INDArray rand(INDArray target, @NonNull @NonNull Distribution dist)
Fill the given ndarray with random numbers drawn from the given distribution- Parameters:
target- target arraydist- distribution to use- Returns:
- the random ndarray with the specified shape
-
rand
public static INDArray rand(INDArray target, double min, double max, @NonNull Random rng)
Fill the given ndarray with random numbers drawn from a uniform distribution using the given RandomGenerator- Parameters:
target- target arraymin- the minimum numbermax- the maximum numberrng- the random generator to use- Returns:
- the given target array
-
randn
public static INDArray randn(INDArray target, long seed)
Fill the given ndarray with random numbers drawn from a normal distribution- Parameters:
target- target array- Returns:
- the given target array
-
randn
public static INDArray randn(INDArray target, @NonNull Random rng)
Fill the given ndarray with random numbers drawn from a normal distribution utilizing the given random generator- Parameters:
target- target arrayrng- the random generator to use- Returns:
- the given target array
-
randomBernoulli
public static INDArray randomBernoulli(double p, @NonNull @lombok.NonNull long... shape)
Generate a random array according to a binomial distribution with probability p: i.e., values 0 with probability (1-p) or value 1 with probability p- Parameters:
p- Probability. Must be in range 0 to 1shape- Shape of the result array- Returns:
- Result array
-
randomBernoulli
public static INDArray randomBernoulli(double p, @NonNull @NonNull INDArray target)
Fill the specified array with values generated according to a binomial distribution with probability p: i.e., values 0 with probability (1-p) or value 1 with probability p- Parameters:
p- Probability. Must be in range 0 to 1target- Result array to place generated values in- Returns:
- Result array
-
randomBinomial
public static INDArray randomBinomial(int nTrials, double p, @NonNull @lombok.NonNull long... shape)
Generate an array with random values generated according to a binomial distribution with the specified number of trials and probability- Parameters:
nTrials- Number of trials. Must be >= 0p- Probability. Must be in range 0 to 1shape- Shape of the result array- Returns:
- Result array
-
randomBinomial
public static INDArray randomBinomial(int nTrials, double p, INDArray target)
Fill the target array with random values generated according to a binomial distribution with the specified number of trials and probability- Parameters:
nTrials- Number of trials. Must be >= 0p- Probability. Must be in range 0 to 1target- Result array- Returns:
- Result array
-
randomExponential
public static INDArray randomExponential(double lambda, long... shape)
Exponential distribution: P(x) = lambda * exp(-lambda * x)- Parameters:
lambda- Must be > 0shape- Shape of the array to generate
-
randomExponential
public static INDArray randomExponential(double lambda, INDArray target)
Exponential distribution: P(x) = lambda * exp(-lambda * x)- Parameters:
lambda- Must be > 0target- Array to hold the result
-
create
public static INDArray create(float[] data)
Creates a row vector with the data- Parameters:
data- the columns of the ndarray- Returns:
- the created ndarray
-
create
public static INDArray create(boolean[] data)
Create a vector based on a java boolean array.- Parameters:
data- java boolean array- Returns:
- the created ndarray.
-
create
public static INDArray create(List<? extends Number> list)
Creates a row vector with the data- Parameters:
list- the columns of the ndarray- Returns:
- the created ndarray
-
create
public static INDArray create(double[] data)
Create double array based on java double array.- Parameters:
data- java double array,- Returns:
- the created ndarray
-
create
public static INDArray create(float[][] data)
Create 2D float array based on java 2d float array.- Parameters:
data- java 2d arrau.- Returns:
- the created ndarray.
-
create
public static INDArray create(float[][] data, char ordering)
Create 2D float array based on java 2d float array and ordering.- Parameters:
data- java 2d arrau.ordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray.
-
create
public static INDArray create(double[][] data)
Create 2D double array based on java 2d double array. and ordering- Parameters:
data- the data to use- Returns:
- the created ndarray.
-
create
public static INDArray create(long[][] data)
Create 2D long array based on java 2d long array.- Parameters:
data- java 2d long array- Returns:
- the created ndarray.
-
create
public static INDArray create(boolean[][] data)
Create 2D boolean array based on java 2d boolean array.- Parameters:
data- java 2d boolean array.- Returns:
- the created ndarray.
-
create
public static INDArray create(boolean[][] data, @NonNull @lombok.NonNull long... shape)
Create a boolean array with given shape based on java 2d boolean array.- Parameters:
data- java 2d boolean array.shape- desired shape of new array.- Returns:
- the created ndarray.
-
create
public static INDArray create(double[][][] data)
Create a 3D double array based on the 3D java double array.- Parameters:
data- java 3d double array.- Returns:
- the created ndarray.
-
create
public static INDArray create(float[][][] data)
Create a 3D float array based on the 3D java float array.- Parameters:
data- java 3d float array.- Returns:
- the created ndarray.
-
create
public static INDArray create(int[][] data)
Create 2D double array based on java 2d double array. and ordering- Parameters:
data- the data to use- Returns:
- the created ndarray.
-
create
public static INDArray create(int[][][] data)
create 3D int array based on 3D java int array.- Parameters:
data- java 3D i array.- Returns:
- the created ndarray.
-
create
public static INDArray create(double[][][][] data)
Create 4D double array based on 4D java double array.- Parameters:
data- java 4D double array.- Returns:
- the created ndarray.
-
create
public static INDArray create(float[][][][] data)
Create 4D float array based on 4D java float array.- Parameters:
data- java 4D float array.- Returns:
- the created ndarray.
-
create
public static INDArray create(int[][][][] data)
Create 4D int array based on 4D java int array.- Parameters:
data- java 4D int array.- Returns:
- the created ndarray.
-
create
public static INDArray create(double[][] data, char ordering)
Create a 2D double array based on a 2D java double array with given ordering.- Parameters:
data- java 2D double array.ordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray,
-
create
public static INDArray create(int columns)
Creates a row vector with the specified number of columns- Parameters:
columns- the columns of the ndarray- Returns:
- the created ndarray
-
create
public static INDArray create(float[] data, char order)
Creates a row vector with the data- Parameters:
data- the columns of the ndarrayorder- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray
-
create
public static INDArray create(double[] data, char order)
Creates a row vector with the data- Parameters:
data- the columns of the ndarrayorder- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray
-
create
public static INDArray create(int columns, char order)
Creates a row vector with the specified number of columns- Parameters:
columns- the columns of the ndarrayorder- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray
-
zeros
public static INDArray zeros(int columns, char order)
Create a 1D float array in soecified order initialized with zero.- Parameters:
columns- number of elements.order- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray.
-
create
public static INDArray create(int[] data, long[] shape, DataType type)
Create an array of the specified type and shape initialized with values from a java 1d array.- Parameters:
data- java array used for initialisation. Must have at least the number of elements required.shape- desired shape of new array.type- Datatype of the new array. Does not need to match int. data will be converted.- Returns:
- the created ndarray.
-
create
public static INDArray create(int[] data, long[] shape, long[] strides, char order, DataType type)
Create an array of the specified type, shape and stride initialized with values from a java 1d array.- Parameters:
data- java array used for initialisation. Must have at least the number of elements required.shape- desired shape of new array.strides- stride, separation of elements in each dimension.order- Fortran 'f' or C/C++ 'c' ordering.type- Datatype of the new array. Does not need to match int. data will be converted.- Returns:
- the created ndarray.
-
create
public static INDArray create(long[] data, long[] shape, long[] strides, char order, DataType type)
-
create
public static INDArray create(double[] data, long[] shape, long[] strides, char order, DataType type)
-
create
public static INDArray create(float[] data, long[] shape, long[] strides, char order, DataType type)
-
create
public static INDArray create(short[] data, long[] shape, long[] strides, char order, DataType type)
-
create
public static INDArray create(byte[] data, long[] shape, long[] strides, char order, DataType type)
-
create
public static INDArray create(boolean[] data, long[] shape, long[] strides, char order, DataType type)
-
empty
public static INDArray empty()
This method creates "empty" INDArray with datatype determined bydataType()- Returns:
- Empty INDArray
-
empty
public static INDArray empty(DataType type)
This method creates "empty" INDArray of the specified datatype- Returns:
- Empty INDArray
-
create
public static INDArray create(float[] data, int[] shape)
Create an ndrray with the specified shape- Parameters:
data- the data to use with tne ndarrayshape- the shape of the array- Returns:
- the created ndarray
-
create
public static INDArray create(float[] data, long... shape)
-
create
public static INDArray create(double[] data, long... shape)
-
create
public static INDArray create(double[] data, int[] shape)
Create an array of the specified shape initialized with values from a java 1d array.- Parameters:
data- the data to use with tne ndarrayshape- the shape of the array- Returns:
- the created ndarray
-
create
public static INDArray create(double[] data, int[] shape, long offset, char ordering)
Create an array. Use specified shape and ordering initialized with values from a java 1d array starting at offset.- Parameters:
data- java array used for initialisation. Must have at least the number of elements required.shape- desired shape of new array.offset- the offset of data array used for initialisation.ordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray.
-
create
public static INDArray create(double[] data, long[] shape, long offset, char ordering)
-
create
public static INDArray create(float[] data, int[] shape, int[] stride, long offset)
Create an array of the specified type, shape and stride initialized with values from a java 1d array using offset.- Parameters:
data- java array used for initialisation. Must have at least the number of elements required.shape- desired shape of new array.stride- stride, separation of elements in each dimension.offset- the offset of data array used for initialisation.- Returns:
- the instance
-
create
public static INDArray create(List<INDArray> list, int... shape)
Creates an array with the specified shape from a list of arrays.- Parameters:
list- list of arrays.shape- desired shape of new array. Must match the resulting shape of combining the list.- Returns:
- the instance
-
create
public static INDArray create(int rows, int columns, int[] stride, long offset)
Creates an ndarray with the specified shape- Parameters:
rows- the rows of the ndarraycolumns- the columns of the ndarraystride- the stride for the ndarrayoffset- the offset of the ndarray- Returns:
- the created ndarray.
-
zeros
public static INDArray zeros(int rows, int columns, int[] stride, long offset)
-
create
public static INDArray create(int[] shape, int[] stride, long offset)
Creates an ndarray with the specified shape- Parameters:
shape- the shape of the ndarraystride- the stride for the ndarrayoffset- the offset of the ndarray- Returns:
- the instance
-
zeros
public static INDArray zeros(int[] shape, int[] stride, long offset)
-
create
public static INDArray create(int rows, int columns, int[] stride)
Creates an ndarray with the specified shape- Parameters:
rows- the rows of the ndarraycolumns- the columns of the ndarraystride- the stride for the ndarray- Returns:
- the instance
-
zeros
public static INDArray zeros(int rows, int columns, int[] stride)
See {@link @see #create(int, int, int[], char)}
-
create
public static INDArray create(int[] shape, int[] stride)
Creates an ndarray with the specified shape- Parameters:
shape- the shape of the ndarraystride- the stride for the ndarray- Returns:
- the instance
-
create
public static INDArray create(long[] shape, long[] stride)
-
zeros
public static INDArray zeros(int[] shape, int[] stride)
-
create
public static INDArray create(int... shape)
Creates an ndarray with the specified shape- Parameters:
shape- the shape of the array- Returns:
- the instance
-
create
public static INDArray create(long... shape)
Creates an ndarray with the specified shape- Parameters:
shape- the shape of the array- Returns:
- the instance
-
create
public static INDArray create(DataType type, long... shape)
Create an array with specified shape and datatype.- Parameters:
type- Datatype of the new array.shape- desired shape of new array.- Returns:
- the created ndarray.
-
create
public static INDArray create(DataBuffer data, int[] shape, int[] strides, long offset)
Create an array based on the data buffer with given shape, stride and offset.- Parameters:
data- data buffer used for initialisation. . Must have at least the number of elements required.shape- desired shape of new array.strides- stride, separation of elements in each dimension.offset- the offset of data array used for initialisation.- Returns:
- the created ndarray.
-
create
public static INDArray create(DataBuffer data, long[] shape, long[] strides, long offset)
-
create
public static INDArray create(DataBuffer data, int[] shape, long offset)
Seecreate(DataBuffer, int[], int[], long). Uses default strides based on shape.
-
create
public static INDArray create(DataBuffer data, int[] newShape, int[] newStride, long offset, char ordering)
-
create
public static INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering)
-
create
public static INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, long ews, char ordering)
Create an array based on the data buffer with given shape, stride and offset.- Parameters:
data- data buffer used for initialisation. . Must have at least the number of elements required.newShape- desired shape of new array.newStride- stride, separation of elements in each dimension.offset- the offset of data array used for initialisation.ews- element wise stride.ordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray.
-
create
public static INDArray create(DataBuffer data, long[] newShape, long[] newStride, long offset, char ordering, DataType dataType)
Create an array based on the data buffer with given shape, stride, offset and data type.- Parameters:
data- data buffer used for initialisation. . Must have at least the number of elements required.newShape- desired shape of new array.newStride- stride, separation of elements in each dimension.offset- the offset of data array used for initialisation.ordering- Fortran 'f' or C/C++ 'c' ordering.dataType- data type.- Returns:
- the created ndarray.
-
create
public static INDArray create(DataBuffer data, int... shape)
Create an array based on the data buffer with given shape.- Parameters:
data- data data buffer used for initialisation. . Must have at least the number of elements required.shape- desired shape of new array.- Returns:
- the created ndarray.
-
create
public static INDArray create(DataBuffer data, long... shape)
-
create
public static INDArray create(DataBuffer buffer)
Create an array based on the data buffer.- Parameters:
buffer- data data buffer used for initialisation.- Returns:
- the created ndarray.
-
create
public static INDArray create(int[] shape, DataType dataType)
Create an array of given shape and data type.- Parameters:
shape- desired shape of new array.dataType- data type.- Returns:
- the created ndarray.
-
zeros
public static INDArray zeros(int[] shape, DataType dataType)
- See Also:
create(int[], DataType)
-
create
public static INDArray create(double[] data, int[] shape, char ordering)
Create an array withgiven shape and ordering based on a java double array.- Parameters:
data- java array used for initialisation. Must have at least the number of elements required.shape- desired shape of new array.ordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created ndarray.
-
create
public static INDArray create(float[] data, int[] shape, char ordering)
-
create
public static INDArray create(float[] data, long[] shape, char ordering)
-
create
public static INDArray create(double[] data, long[] shape, char ordering)
-
create
public static INDArray create(long[] shape, long[] stride, long offset, char ordering)
Creates an ndarray with the specified shape- Parameters:
shape- the shape of the ndarraystride- the stride for the ndarrayoffset- the offset of the ndarray- Returns:
- the instance
-
create
public static INDArray create(int rows, int columns, int[] stride, char ordering)
Create a 2D array with given rows, columns, stride and ordering.- Parameters:
rows- number of rows.columns- number of columnsstride- stride, separation of elements in each dimension.ordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created array.
-
create
public static INDArray create(int[] shape, int[] stride, char ordering)
Creates an ndarray with the specified shape- Parameters:
shape- the shape of the ndarraystride- the stride for the ndarrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the instance
-
create
public static INDArray create(long[] shape, long[] stride, char ordering)
-
create
public static INDArray create(long rows, long columns, char ordering)
Creates an ndarray with the specified shape- Parameters:
rows- the rows of the ndarraycolumns- the columns of the ndarrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the instance
-
zeros
public static INDArray zeros(int rows, int columns, char ordering)
Create a 2D array initialized with zeros.- Parameters:
rows- the rows of the ndarraycolumns- the columns of the ndarrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the instance
-
create
public static INDArray create(@NonNull @lombok.NonNull int[] shape, char ordering)
Creates an ndarray with the specified shape- Parameters:
shape- the shape of the arrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the instance
-
create
public static INDArray create(@NonNull @lombok.NonNull long[] shape, char ordering)
Create an array with given shape and ordering.- Parameters:
shape- the shape of the arrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created array.
-
create
public static INDArray create(DataType dataType, @NonNull @lombok.NonNull long[] shape, long[] strides, char ordering)
Create an array with given shape, stride and ordering.- Parameters:
dataType- data type.shape- the shape of the arraystrides- stride, separation of elements in each dimension.ordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created array.
-
create
public static INDArray create(@NonNull @NonNull DataType dataType, @NonNull @lombok.NonNull long[] shape, char ordering)
Create an array with given data type shape and ordering.- Parameters:
dataType- data type.shape- the shape of the arrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created array.
-
checkShapeValues
public static void checkShapeValues(long... shape)
Throws exception on negative shape values.- Parameters:
shape- to check
-
createUninitialized
public static INDArray createUninitialized(int[] shape, char ordering)
Creates an *uninitialized* array with the specified shape and ordering.
NOTE: The underlying memory (DataBuffer) will not be initialized. Don't use this unless you know what you are doing.- Parameters:
shape- the shape of the arrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the instance
-
createUninitialized
public static INDArray createUninitialized(DataType type, long[] shape, char ordering)
Creates an *uninitialized* array with the specified data type, shape and ordering.- Parameters:
type- data typeshape- the shape of the arrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created array.
-
createUninitialized
public static INDArray createUninitialized(long[] shape, char ordering)
Creates an *uninitialized* array with the specified shape and ordering.- Parameters:
shape- the shape of the arrayordering- Fortran 'f' or C/C++ 'c' ordering.- Returns:
- the created array.
-
createUninitialized
public static INDArray createUninitialized(int... shape)
-
createUninitialized
public static INDArray createUninitialized(long... shape)
Creates an *uninitialized* ndarray with the specified shape and default ordering.
NOTE: The underlying memory (DataBuffer) will not be initialized. Don't use this unless you know what you are doing.- Parameters:
shape- the shape of the array- Returns:
- the instance
-
createUninitialized
public static INDArray createUninitialized(long length)
This method creates an *uninitialized* ndarray of specified length and default ordering. PLEASE NOTE: Do not use this method unless you're 100% sure why you use it.- Parameters:
length- length of array to create- Returns:
- the created INDArray
-
createUninitializedDetached
public static INDArray createUninitializedDetached(DataType dataType, char ordering, long... shape)
Create an uninitialized ndArray. Detached from workspace.- Parameters:
dataType- data type. Exceptions will be thrown for UTF8, COMPRESSED and UNKNOWN data types.ordering- Fortran 'f' or C/C++ 'c' ordering.shape- the shape of the array.- Returns:
- the created detached array.
-
createUninitializedDetached
public static INDArray createUninitializedDetached(DataType dataType, long... shape)
SeecreateUninitializedDetached(DataType, char, long...)with default ordering.
-
zeros
public static INDArray zeros(DataType dataType, @NonNull @lombok.NonNull long... shape)
Creates an array with the specified data tyoe and shape initialized with zero.- Parameters:
dataType- data type.shape- the shape of the array- Returns:
- the created array.
-
valueArrayOf
public static INDArray valueArrayOf(int[] shape, double value)
Creates an ndarray with the specified value as the only value in the ndarray. Some people may know this as np.full- Parameters:
shape- the shape of the arrayvalue- the value to assign- Returns:
- the created ndarray
-
valueArrayOf
public static INDArray valueArrayOf(long[] shape, float value)
Creates an ndarray with the specified value as the only value in the FLOAT32 datatype NDArray. Equivalent to Numpy's np.full- Parameters:
shape- the shape of the arrayvalue- the value to assign- Returns:
- the created ndarray
-
valueArrayOf
public static INDArray valueArrayOf(long[] shape, int value)
Creates an ndarray with the specified value as the only value in the INTEGER datatype NDArray. Equivalent to Numpy's np.full- Parameters:
shape- the shape of the arrayvalue- the value to assign- Returns:
- the created ndarray
-
valueArrayOf
public static INDArray valueArrayOf(long[] shape, double value)
-
valueArrayOf
public static INDArray valueArrayOf(long[] shape, double value, DataType type)
Creates an ndarray with the specified value as the only value in the ndarray. Some people may know this as np.full- Parameters:
shape- the shape of the arrayvalue- the value to assigntype- data type- Returns:
- the created ndarray
-
valueArrayOf
public static INDArray valueArrayOf(long num, double value)
Creates a row vector ndarray with the specified value as the only value in the ndarray Some people may know this as np.full- Parameters:
num- number of columnsvalue- the value to assign- Returns:
- the created ndarray
-
valueArrayOf
public static INDArray valueArrayOf(long rows, long columns, double value)
Creates a row vector with the specified number of columns Some people may know this as np.full- Parameters:
rows- the number of rows in the matrixcolumns- the columns of the ndarrayvalue- the value to assign- Returns:
- the created ndarray
-
zerosLike
public static INDArray zerosLike(INDArray arr)
Empty like- Parameters:
arr- the array to create the ones like- Returns:
- ones in the shape of the given array
-
onesLike
public static INDArray onesLike(INDArray arr)
Ones like- Parameters:
arr- the array to create the ones like- Returns:
- ones in the shape of the given array
-
ones
public static INDArray ones(DataType dataType, @NonNull @lombok.NonNull long... shape)
Creates an array with the specified datatype and shape, with values all set to 1- Parameters:
shape- Shape fo the array- Returns:
- the created ndarray
-
hstack
public static INDArray hstack(@NonNull @NonNull INDArray... arrs)
Concatenates two matrices horizontally. Matrices must have identical numbers of rows.- Parameters:
arrs- the first matrix to concat
-
hstack
public static INDArray hstack(Collection<INDArray> arrs)
Concatenates two matrices horizontally. Matrices must have identical numbers of rows.- Parameters:
arrs- the first matrix to concat
-
vstack
public static INDArray vstack(@NonNull @NonNull INDArray... arrs)
Concatenates two matrices vertically. Matrices must have identical numbers of columns.
Note that for vstack on rank 1 arrays, this is equivalent topile(INDArray...). Example: vstack([3],[3]) -> [2,3]- Parameters:
arrs- Arrays to vstack
-
vstack
public static INDArray vstack(Collection<INDArray> arrs)
Concatenates two matrices vertically. Matrices must have identical numbers of columns.
Note that for vstack on rank 1 arrays, this is equivalent topile(INDArray...). Example: vstack([3],[3]) -> [2,3]- Parameters:
arrs- Arrays to vstack
-
averageAndPropagate
public static INDArray averageAndPropagate(INDArray[] arrays)
This method averages input arrays, and returns averaged array. On top of that, averaged array is propagated to all input arrays- Parameters:
arrays- arrays to average- Returns:
- averaged arrays
-
averageAndPropagate
public static INDArray averageAndPropagate(Collection<INDArray> arrays)
This method averages input arrays, and returns averaged array. On top of that, averaged array is propagated to all input arrays- Parameters:
arrays- arrays to average- Returns:
- averaged arrays
-
averageAndPropagate
public static INDArray averageAndPropagate(INDArray target, Collection<INDArray> arrays)
This method averages input arrays, and returns averaged array. On top of that, averaged array is propagated to all input arrays- Parameters:
arrays- arrays to average- Returns:
- averaged arrays
-
stripOnes
public static INDArray stripOnes(INDArray toStrip)
Reshapes an ndarray to remove leading 1s- Parameters:
toStrip- the ndarray to newShapeNoCopy- Returns:
- the reshaped ndarray
-
accumulate
public static INDArray accumulate(@NonNull @NonNull INDArray... arrays)
This method sums given arrays and stores them to a new array- Parameters:
arrays- array to accumulate- Returns:
- accumulated array.
-
accumulate
public static INDArray accumulate(INDArray target, Collection<INDArray> arrays)
This method sums given arrays and stores them to a given target array- Parameters:
target- result arrayarrays- arrays to sum- Returns:
- result array
-
accumulate
public static INDArray accumulate(INDArray target, INDArray[] arrays)
This method sums given arrays and stores them to a given target array- Parameters:
target- result arrayarrays- arrays to sum- Returns:
- result array
-
pullRows
public static INDArray pullRows(INDArray source, int sourceDimension, @NonNull @lombok.NonNull int... indexes)
This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes- Parameters:
source- source tensorsourceDimension- dimension of source tensorindexes- indexes from source array- Returns:
- result array
-
pullRows
public static INDArray pullRows(INDArray source, int sourceDimension, int[] indexes, char order)
This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes- Parameters:
source- source tensorsourceDimension- dimension of source tensorindexes- indexes from source array- Returns:
- concatenated array
-
pullRows
public static INDArray pullRows(INDArray source, INDArray destination, int sourceDimension, @NonNull @lombok.NonNull int... indexes)
This method produces concatenated array, that consist from tensors, fetched from source array, against some dimension and specified indexes. The concatenated arrays are placed in the specified array.- Parameters:
source- source tensordestination- Destination tensor (result will be placed here)sourceDimension- dimension of source tensorindexes- indexes from source array- Returns:
- Destination array with specified tensors
-
stack
public static INDArray stack(int axis, @NonNull @NonNull INDArray... values)
Stack a set of N SDVariables of rank X into one rank X+1 variable. If inputs have shape [a,b,c] then output has shape:
axis = 0: [N,a,b,c]
axis = 1: [a,N,b,c]
axis = 2: [a,b,N,c]
axis = 3: [a,b,c,N]- Parameters:
axis- Axis to stack onvalues- Input variables to stack. Must have the same shape for all inputs- Returns:
- Output array
- See Also:
concat(int, INDArray...)
-
concat
public static INDArray concat(int dimension, @NonNull @NonNull INDArray... toConcat)
Concatenate ndarrays along a dimension- Parameters:
dimension- the dimension to concatenate alongtoConcat- the ndarrays to concat- Returns:
- the merged ndarrays with an output shape of the ndarray shapes save the dimension shape specified which is then the sum of the sizes along that dimension
-
specialConcat
public static INDArray specialConcat(int dimension, @NonNull @NonNull INDArray... toConcat)
Concatenate ndarrays along a dimension PLEASE NOTE: This method is special for GPU backend, it works on HOST side only.- Parameters:
dimension- dimensiontoConcat- arrays to concatenate- Returns:
- concatenated arrays.
-
zeros
public static INDArray zeros(int[] shape, char order)
Create an ndarray of zeros- Parameters:
shape- the shape of the array- Returns:
- an ndarray with ones filled in
-
zeros
public static INDArray zeros(long[] shape, char order)
-
zeros
public static INDArray zeros(@NonNull @lombok.NonNull int... shape)
Create an ndarray of zeros- Parameters:
shape- the shape of the array- Returns:
- an ndarray with ones filled in
-
zeros
public static INDArray zeros(@NonNull @lombok.NonNull long... shape)
Create an ndarray of zeros- Parameters:
shape- the shape of the array- Returns:
- an ndarray with ones filled in
-
ones
public static INDArray ones(@NonNull @lombok.NonNull int... shape)
Create an ndarray of ones- Parameters:
shape- the shape of the array- Returns:
- an ndarray with ones filled in
-
ones
public static INDArray ones(@NonNull @lombok.NonNull long... shape)
-
scalar
public static INDArray scalar(Number value)
Create a scalar ndarray with the specified value- Parameters:
value- the value to initialize the scalar with- Returns:
- the created ndarray
-
scalar
public static INDArray scalar(DataType dataType, Number value)
Create a scalar ndarray with the specified value and datatype- Parameters:
value- the value to initialize the scalar with- Returns:
- the created ndarray
-
scalar
public static INDArray scalar(double value)
Create a scalar nd array with the specified value- Parameters:
value- the value of the scalar- Returns:
- the scalar nd array
-
scalar
public static INDArray scalar(float value)
Create a scalar NDArray with the specified value and FLOAT datatype- Parameters:
value- the value of the scalar- Returns:
- the scalar nd array
-
scalar
public static INDArray scalar(boolean value)
Create a scalar NDArray with the specified value and BOOLEAN datatype- Parameters:
value- the value of the scalar- Returns:
- the scalar nd array
-
scalar
public static INDArray scalar(int value)
Create a scalar NDArray with the specified value and INT datatype- Parameters:
value- the value of the scalar- Returns:
- the scalar nd array
-
scalar
public static INDArray scalar(long value)
Create a scalar NDArray with the specified value and LONG datatype- Parameters:
value- the value of the scalar- Returns:
- the scalar nd array
-
getStrides
public static int[] getStrides(int[] shape, char order)Get the strides for the given order and shape- Parameters:
shape- the shape of the arrayorder- the order to getScalar the strides for- Returns:
- the strides for the given shape and order
-
getStrides
public static long[] getStrides(long[] shape, char order)
-
getStrides
public static int[] getStrides(@NonNull @lombok.NonNull int... shape)Get the strides based on the shape and NDArrays.order()- Parameters:
shape- the shape of the array- Returns:
- the strides for the given shape and order specified by NDArrays.order()
-
getStrides
public static long[] getStrides(@NonNull @lombok.NonNull long... shape)Get the strides based on the shape and NDArrays.order()- Parameters:
shape- the shape of the array- Returns:
- the strides for the given shape and order specified by NDArrays.order()
-
tile
public static INDArray tile(INDArray tile, @NonNull @lombok.NonNull int... repeat)
An alias for repmat- Parameters:
tile- the ndarray to tilerepeat- the shape to repeat- Returns:
- the tiled ndarray
-
initWithBackend
public void initWithBackend(Nd4jBackend backend)
Initialize with the specific backend- Parameters:
backend- the backend to initialize with
-
getShapeInfoProvider
public static ShapeInfoProvider getShapeInfoProvider()
- Returns:
- Shape info provider
-
getConstantHandler
public static ConstantHandler getConstantHandler()
- Returns:
- constant handler
-
getAffinityManager
public static AffinityManager getAffinityManager()
- Returns:
- affinity manager
-
getNDArrayFactory
public static NDArrayFactory getNDArrayFactory()
- Returns:
- NDArrayFactory
-
getCompressor
public static BasicNDArrayCompressor getCompressor()
This method returns BasicNDArrayCompressor instance, suitable for NDArray compression/decompression at runtime- Returns:
- BasicNDArrayCompressor instance
-
getMemoryManager
public static MemoryManager getMemoryManager()
This method returns backend-specific MemoryManager implementation, for low-level memory management- Returns:
- MemoryManager
-
sizeOfDataType
@Deprecated public static int sizeOfDataType()
Deprecated.Use DataType.width()This method returns sizeOf(currentDataType), in bytes- Returns:
- number of bytes per element
-
sizeOfDataType
public static int sizeOfDataType(DataType dtype)
This method returns size of element for specified dataType, in bytes- Parameters:
dtype- number of bytes per element- Returns:
- element size
-
enableFallbackMode
public static void enableFallbackMode(boolean reallyEnable)
This method enables fallback to safe-mode for specific operations. Use of this method will reduce performance. Currently supported operations are: 1) CPU GEMM PLEASE NOTE: Do not use this method, unless you have too.- Parameters:
reallyEnable- fallback mode
-
isFallbackModeEnabled
public static boolean isFallbackModeEnabled()
This method checks, if fallback mode was enabled.- Returns:
- fallback mode
-
getWorkspaceManager
public static MemoryWorkspaceManager getWorkspaceManager()
This method returns WorkspaceManager implementation to be used within this JVM process- Returns:
- WorkspaceManager
-
pile
public static INDArray pile(@NonNull @NonNull INDArray... arrays)
This method stacks vertically examples with the same shape, increasing result dimensionality. I.e. if you provide bunch of 3D tensors, output will be 4D tensor. Alignment is always applied to axis 0.- Parameters:
arrays- arrays to stack- Returns:
- stacked arrays
-
pile
public static INDArray pile(@NonNull @NonNull Collection<INDArray> arrays)
This method stacks vertically examples with the same shape, increasing result dimensionality. I.e. if you provide bunch of 3D tensors, output will be 4D tensor. Alignment is always applied to axis 0.- Parameters:
arrays- arrays to stack- Returns:
- stacked array
-
tear
public static INDArray[] tear(INDArray tensor, @NonNull @lombok.NonNull int... dimensions)
This method does the opposite to pile/vstack/hstack - it returns independent TAD copies along given dimensions- Parameters:
tensor- Array to teardimensions- dimensions- Returns:
- Array copies
-
triu
public static INDArray triu(INDArray m, int k)
Upper triangle of an array. Referenced from the numpy docs: Return a copy of a matrix with the elements below the `k`-th diagonal zeroed. Please refer to the documentation for `tril` for further details. See Also -------- tril : lower triangle of an array Examples -------- >>> np.triu([[1,2,3],[4,5,6],[7,8,9],[10,11,12]], -1) array([[ 1, 2, 3], [ 4, 5, 6], [ 0, 8, 9], [ 0, 0, 12]]) """ m = asanyarray(m) mask = tri(*m.shape[-2:], k=k-1, dtype=bool) return where(mask, zeros(1, m.dtype), m)- Parameters:
m- source arrayk- to zero below the k-th diagonal- Returns:
- copy with elements below the `k`-th diagonal zeroed.
-
tri
public static INDArray tri(int n)
Seetri(int,int,int)with m = n, k=0.
-
tri
public static INDArray tri(int n, int k)
Seetri(int,int,int)with m = n.
-
tri
public static INDArray tri(int n, int m, int k)
Like the scipy function tri. From the scipy documentation: An array with ones at and below the given diagonal and zeros elsewhere.- Parameters:
n- number of rows in the arraym- number of columns in the array ( can be just equal to n)k- The sub-diagonal at and below which the array is filled. `k` = 0 is the main diagonal, while `k` < 0 is below it, and `k` > 0 is above. The default is 0.- Returns:
- array with ones at and below the given diagonal and zeros elsewhere
-
where
public static INDArray[] where(INDArray condition, INDArray x, INDArray y)
Similar to numpy.where operation. Supports two modes of operation:
(a) condition array only is provided: returns N 1d arrays of the indices where "condition" values are non-zero. Specifically, each output out has shape [numNonZero(condition)], such that in[out[0], ..., out[n-1]] is non-zero
(b) all 3 arrays are provided: returnsout[i] = (condition[i] != 0 ? x[i] : y[i])- Parameters:
condition- Condition arrayx- X array. If null, y must be null also.y- Y array. If null, x must be null also- Returns:
- Either the indices where condition is non-zero (if x and y are null), or values from x/y depending on value of condition
-
writeAsNumpy
public static void writeAsNumpy(INDArray arr, File file) throws IOException
- Parameters:
arr- the array to write in Numpy .npy formatfile- the file to write to- Throws:
IOException- if an error occurs when writing the file
-
convertToNumpy
public static org.bytedeco.javacpp.Pointer convertToNumpy(INDArray arr)
Converts anINDArrayto a numpy struct.- Parameters:
arr- the array to convert- Returns:
- a pointer to the numpy struct
-
writeAsNumpy
public static void writeAsNumpy(INDArray arr, OutputStream writeTo) throws IOException
Writes an array to an output stream- Parameters:
arr- the array to writewriteTo- the output stream to write to- Throws:
IOException
-
createFromNpyPointer
public static INDArray createFromNpyPointer(org.bytedeco.javacpp.Pointer pointer)
Create from an in memory numpy pointer- Parameters:
pointer- the pointer to the numpy array- Returns:
- an ndarray created from the in memory numpy pointer
-
readNpy
public static INDArray readNpy(@NonNull @NonNull String path)
Create an INDArray from a given Numpy .npy file.- Parameters:
path- Path to the .npy file to read- Returns:
- the created ndarray
-
readNpy
public static INDArray readNpy(@NonNull @NonNull File file)
Create an INDArray from a given Numpy .npy file.- Parameters:
file- the file to create the ndarray from- Returns:
- the created ndarray
-
createFromNpyFile
public static INDArray createFromNpyFile(@NonNull @NonNull File file)
Create an INDArray from a given Numpy .npy file.- Parameters:
file- the file to create the ndarray from- Returns:
- the created ndarray
-
createFromNpzFile
public static Map<String,INDArray> createFromNpzFile(File file) throws Exception
- Throws:
Exception
-
createNpyFromInputStream
public static INDArray createNpyFromInputStream(@NonNull @NonNull InputStream is) throws IOException
Create a numpy array based on the passed in input stream- Parameters:
is- the input stream to read- Returns:
- the loaded ndarray
- Throws:
IOException
-
createNpyFromByteArray
public static INDArray createNpyFromByteArray(@NonNull @lombok.NonNull byte[] input)
Create anINDArrayfrom the given numpy input.
The numpy input follows the format: https://docs.scipy.org/doc/numpy-1.14.0/neps/npy-format.html- Parameters:
input- the input byte array with the npy format- Returns:
- the equivalent
INDArray
-
toNpyByteArray
public static byte[] toNpyByteArray(INDArray input)
Converts anINDArrayto a byte array- Parameters:
input- the input array- Returns:
- the
INDArrayas a byte array with the numpy format. For more on the format, see: https://docs.scipy.org/doc/numpy-1.14.0/neps/npy-format.html
-
defaultFloatingPointType
public static DataType defaultFloatingPointType()
-
isPrecisionBoostAllowed
public static boolean isPrecisionBoostAllowed()
-
create
public static INDArray create(@NonNull @NonNull Collection<String> strings, long... shape)
-
create
public static INDArray create(@NonNull @NonNull Collection<String> strings, long[] shape, char order)
-
createFromArray
public static INDArray createFromArray(double... array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(float... array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(int... array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(short... array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(byte... array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(long... array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(boolean... array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with BOOL data type
-
createFromArray
public static INDArray createFromArray(double[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(float[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(long[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(int[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(short[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(byte[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(boolean[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with BOOL data type
-
createFromArray
public static INDArray createFromArray(double[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(float[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(long[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(int[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(short[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(byte[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(boolean[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with BOOL data type
-
createFromArray
public static INDArray createFromArray(double[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(float[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(long[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(int[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(short[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(byte[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(boolean[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with BOOL data type
-
getDeallocatorService
public static DeallocatorService getDeallocatorService()
-
createFromArray
public static INDArray createFromArray(Double[] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(Float[] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(Integer[] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(Short[] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(Byte[] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(Long[] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(Boolean[] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 1D INDArray with BOOL data type
-
createFromArray
public static INDArray createFromArray(Double[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(Float[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(Integer[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(Short[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(Byte[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(Long[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(Boolean[][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 2D INDArray with BOOL data type
-
createFromArray
public static INDArray createFromArray(Double[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(Float[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(Integer[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(Short[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(Byte[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(Long[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(Boolean[][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 3D INDArray with BOOL data type
-
createFromArray
public static INDArray createFromArray(Double[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with DOUBLE data type
-
createFromArray
public static INDArray createFromArray(Float[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with FLOAT data type
-
createFromArray
public static INDArray createFromArray(Integer[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT32 data type
-
createFromArray
public static INDArray createFromArray(Short[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT16 data type
-
createFromArray
public static INDArray createFromArray(Byte[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT8 data type
-
createFromArray
public static INDArray createFromArray(Long[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with INT64 data type
-
createFromArray
public static INDArray createFromArray(Boolean[][][][] array)
This method creates INDArray from provided jvm array- Parameters:
array- jvm array- Returns:
- 4D INDArray with BOOL data type
-
isExperimentalMode
public static boolean isExperimentalMode()
-
exec
public static INDArray exec(Op op)
Execute the operation and return the result- Parameters:
op- the operation to execute
-
exec
public static INDArray[] exec(CustomOp op)
Execute the operation and return the result- Parameters:
op- the operation to execute
-
exec
public static INDArray[] exec(CustomOp op, OpContext context)
Execute the operation and return the result- Parameters:
op- the operation to execute
-
scatterUpdate
@Deprecated public static void scatterUpdate(ScatterUpdate.UpdateOp op, @NonNull @NonNull INDArray array, @NonNull @NonNull INDArray indices, @NonNull @NonNull INDArray updates, int... axis)
Deprecated.This method applies ScatterUpdate op
-
-