本文整理了Java中org.nd4j.linalg.factory.Nd4j.eye()
方法的一些代码示例,展示了Nd4j.eye()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.eye()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:eye
[英]Create the identity ndarray
[中]创建标识数组
代码示例来源:origin: deeplearning4j/nd4j
@Override
public INDArray doCreate(long[] shape, INDArray paramsView) {
if(shape.length != 2 || shape[0] != shape[1]){
throw new IllegalStateException("Cannot use IDENTITY init with parameters of shape "
+ Arrays.toString(shape) + ": weights must be a square matrix for identity");
}
if(order() == Nd4j.order()){
return Nd4j.eye(shape[0]);
} else {
return Nd4j.createUninitialized(shape, order()).assign(Nd4j.eye(shape[0]));
}
}
代码示例来源:origin: deeplearning4j/nd4j
/**
* Calculates the principal component vectors and their eigenvalues (lambda) for the covariance matrix.
* The result includes two things: the eigenvectors (modes) as result[0] and the eigenvalues (lambda)
* as result[1].
*
* @param cov The covariance matrix (calculated with the covarianceMatrix(in) method)
* @return Array INDArray[2] "result". The principal component vectors in decreasing flexibility are
* the columns of element 0 and the eigenvalues are element 1.
*/
public static INDArray[] principalComponents(INDArray cov) {
assert cov.rows() == cov.columns();
INDArray[] result = new INDArray[2];
result[0] = Nd4j.eye(cov.rows());
result[1] = Eigen.symmetricGeneralizedEigenvalues(result[0], cov, true);
return result;
}
代码示例来源:origin: deeplearning4j/dl4j-examples
INDArray identityMatrix = Nd4j.eye(3);
System.out.println("\n\n\nNd4j.eye(3):\n" + identityMatrix);
INDArray linspace = Nd4j.linspace(1,10,10); //Values 1 to 10, in 10 steps
代码示例来源:origin: deeplearning4j/nd4j
if (n == 0) {
if (dup)
return Nd4j.eye(in.rows());
else
return in.assign(Nd4j.eye(in.rows()));
代码示例来源:origin: deeplearning4j/nd4j
@Override
public INDArray getPFactor(int M, INDArray ipiv) {
// The simplest permutation is the identity matrix
INDArray P = Nd4j.eye(M); // result is a square matrix with given size
for (int i = 0; i < ipiv.length(); i++) {
int pivot = ipiv.getInt(i) - 1; // Did we swap row #i with anything?
if (pivot > i) { // don't reswap when we get lower down in the vector
INDArray v1 = P.getColumn(i).dup(); // because of row vs col major order we'll ...
INDArray v2 = P.getColumn(pivot); // ... make a transposed matrix immediately
P.putColumn(i, v2);
P.putColumn(pivot, v1); // note dup() above is required - getColumn() is a 'view'
}
}
return P; // the permutation matrix - contains a single 1 in any row and column
}
代码示例来源:origin: deeplearning4j/dl4j-examples
print("3x4 ones", threeByFourOnes);
INDArray fiveByFiveIdentity = Nd4j.eye(5);
print("5x5 Identity", fiveByFiveIdentity);
代码示例来源:origin: improbable-research/keanu
public static INDArray eye(long n, DataBuffer.Type bufferType) {
Nd4j.setDataType(bufferType);
if (n == 0) {
return scalar(1.0, bufferType);
}
return Nd4j.eye(n);
}
代码示例来源:origin: org.nd4j/nd4j-api
/**
* Calculates the principal component vectors and their eigenvalues (lambda) for the covariance matrix.
* The result includes two things: the eigenvectors (modes) as result[0] and the eigenvalues (lambda)
* as result[1].
*
* @param cov The covariance matrix (calculated with the covarianceMatrix(in) method)
* @return Array INDArray[2] "result". The principal component vectors in decreasing flexibility are
* the columns of element 0 and the eigenvalues are element 1.
*/
public static INDArray[] principalComponents(INDArray cov) {
assert cov.rows() == cov.columns();
INDArray[] result = new INDArray[2];
result[0] = Nd4j.eye(cov.rows());
result[1] = Eigen.symmetricGeneralizedEigenvalues(result[0], cov, true);
return result;
}
代码示例来源:origin: org.nd4j/nd4j-api
assert in.rows() == in.columns();
if (n == 0) {
if (dup) return Nd4j.eye(in.rows());
else return in.assign(Nd4j.eye(in.rows()));
代码示例来源:origin: org.nd4j/nd4j-api
@Override
public INDArray getPFactor(int M, INDArray ipiv) {
// The simplest permutation is the identity matrix
INDArray P = Nd4j.eye(M); // result is a square matrix with given size
for (int i = 0; i < ipiv.length(); i++) {
int pivot = ipiv.getInt(i) - 1; // Did we swap row #i with anything?
if (pivot > i) { // don't reswap when we get lower down in the vector
INDArray v1 = P.getColumn(i).dup(); // because of row vs col major order we'll ...
INDArray v2 = P.getColumn(pivot); // ... make a transposed matrix immediately
P.putColumn(i, v2);
P.putColumn(pivot, v1); // note dup() above is required - getColumn() is a 'view'
}
}
return P; // the permutation matrix - contains a single 1 in any row and column
}
内容来源于网络,如有侵权,请联系作者删除!