In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "summary of the basic operation of ND4J", the content of the explanation is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn the "summary of the basic operation of ND4J"!
1. The storage structure of ND4J in memory
For ND4J, all data is stored in out-of-heap memory, which is one-dimensional continuous memory. INDArray just points to this continuous memory space and maps continuous memory into a tensor. ND4J defines two sorting rules: C order and F order,C order for row priority and F order for column priority. The following figure shows the memory storage of ND4J.
As can be seen in the above figure, but the tensor is multi-dimensional, and the corresponding physical storage is one-dimensional continuous memory space. NDArray is pointing to this continuous address, which is where ND4J is powerful. For all kinds of matrix operations, such as matrix transpose, matrix scalar and so on, it can be easily realized without having to dup a giant array. High performance is also shown in this elegant design.
Second, the basic operation of ND4J
1. Addition
INDArray add (INDArray other): elements are added and the returned tensor is copied.
INDArray addi (INDArray other): element correspondence and addition. Unlike the above, the return value is not a copied new array, but replaces the original memory data with the calculation result.
INDArray add (Number n): add a scalar to each element
INDArray addi (Number n): add a scalar to each element and overwrite the original array
2. Subtraction
INDArray sub (Number n): subtract a scalar from each element
INDArray subi (Number n): each element subtracts the scalar and overwrites the original array
INDArray sub (INDArray other): subtraction of corresponding elements
INDArray subi (INDArray other): subtracts the corresponding elements and overwrites the original array
3. Multiplication
There are two kinds of multiplication, corresponding element multiplication and matrix multiplication.
INDArray mul (INDArray other): multiply the corresponding elements
INDArray muli (INDArray other): multiplies the corresponding elements and overwrites the original array
INDArray mmul (INDArray other): Matrix multiplication
INDArray mmuli (INDArray other): multiplies matrices and overwrites the original array
4. Division
INDArray div (INDArray other): division of corresponding elements
INDArray divi (INDArray other): divides the corresponding elements and overwrites the original array
INDArray div (Number n): each element divided by a scalar
INDArray divi (Number n): each element is divided by a scalar and overwrites the original array
5. Matrix transpose
INDArray transpose ()
INDArray transposei ()
To sum up: the following method, which ends with I, indicates in place, that is, data that will overwrite the original memory space, which means "pass reference".
6. Tensor creation
Many static methods are defined in the Nd4j class to create N-dimensional tensors, for example: Nd4j.zeros (nRows, nColumns)
Public static INDArray zeros (int rows, int columns): create a tensor with all elements 0
Public static INDArray ones (int rows, int columns): create a tensor with all elements 1
Public static INDArray hstack (INDArray... Arrs): connect multiple matrices horizontally, and the matrix must have the same row
Public static INDArray vstack (INDArray... Arrs): join multiple matrices vertically, and the matrix must have the same column
Public static INDArray rand (int rows, int columns): tensor of random corresponding shape
Public static INDArray rand (int [] shape): tensor of random corresponding shape
7. Tensor setting value
INDArray putScalar (int [] I, double value): set scalar at the corresponding position
INDArray putScalar (int row, int col, double value): sets the scalar at the corresponding row
INDArray put (INDArrayIndex [] indices, INDArray element): set INDArray at the corresponding dimension
8. Other operations
INDArray reshape (int... NewShape): redefine the tensor shape
Here only enumerates some common operations of ND4J, ND4J also defines many flexible operations corresponding to tensors, such as summation, averaging, maximum and minimum, BooleanIndexing replacing tensor values according to conditions, common function operations (sigmoid, tanh, etc.), for more details, you can take a closer look at DL4J example or unit tests to experience this excellent tensor operation library.
Thank you for your reading, the above is the "summary of the basic operation of ND4J" content, after the study of this article, I believe you have a deeper understanding of the basic operation of ND4J summary of this problem, the specific use of the need for you to practice and verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.