本文整理了Java中org.ujmp.core.Matrix.deleteRows()
方法的一些代码示例,展示了Matrix.deleteRows()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.deleteRows()
方法的具体详情如下:
包路径:org.ujmp.core.Matrix
类名称:Matrix
方法名:deleteRows
暂无
代码示例来源:origin: ujmp/universal-java-matrix-package
Matrix xdel = x.deleteRows(Ret.NEW, missingRows);
Matrix bias1 = DenseDoubleMatrix2D.Factory.ones(xdel.getRowCount(), 1);
Matrix xtrain = Matrix.Factory.horCat(xdel, bias1);
Matrix ytrain = y.deleteRows(Ret.NEW, missingRows);
代码示例来源:origin: ujmp/universal-java-matrix-package
private static Matrix replaceInColumn(Matrix original, Matrix firstGuess, long column) {
Matrix x = firstGuess.deleteColumns(Ret.NEW, column);
Matrix y = original.selectColumns(Ret.NEW, column);
List<Long> missingRows = new ArrayList<Long>();
for (long i = y.getRowCount(); --i >= 0;) {
double v = y.getAsDouble(i, 0);
if (MathUtil.isNaNOrInfinite(v)) {
missingRows.add(i);
}
}
if (missingRows.isEmpty()) {
return y;
}
Matrix xdel = x.deleteRows(Ret.NEW, missingRows);
DenseDoubleMatrix2D bias1 = DenseDoubleMatrix2D.Factory.ones(xdel.getRowCount(), 1);
Matrix xtrain = Matrix.Factory.horCat(xdel, bias1);
Matrix ytrain = y.deleteRows(Ret.NEW, missingRows);
Matrix xinv = xtrain.pinv();
Matrix b = xinv.mtimes(ytrain);
DenseDoubleMatrix2D bias2 = DenseDoubleMatrix2D.Factory.ones(x.getRowCount(), 1);
Matrix yPredicted = Matrix.Factory.horCat(x, bias2).mtimes(b);
// set non-missing values back to original values
for (int row = 0; row < y.getRowCount(); row++) {
double v = y.getAsDouble(row, 0);
if (!Double.isNaN(v)) {
yPredicted.setAsDouble(v, row, 0);
}
}
return yPredicted;
}
代码示例来源:origin: ujmp/universal-java-matrix-package
Matrix data = m.deleteRows(Ret.NEW, 0); // remove label
Matrix columnLabels = m.selectRows(Ret.NEW, 0); // extract label
代码示例来源:origin: ujmp/universal-java-matrix-package
public ExtractAnnotation(Matrix m, int dim) {
super(dim, m);
size = Coordinates.copyOf(m.getSize());
size[dim]--;
setMetaData(new DefaultMapMatrix<String, Object>(new TreeMap<String, Object>()));
getMetaData().put(Matrix.LABEL, m.getLabelObject());
if (dim == ROW) {
MapMatrix<String, Object> a = m.getMetaData();
if (a != null) {
Matrix ai = (Matrix) a.get(Matrix.DIMENSIONMETADATA + COLUMN);
if (ai != null) {
ai = ai.deleteRows(Ret.NEW, 0);
getMetaData().put(Matrix.DIMENSIONMETADATA + COLUMN, ai);
}
}
getMetaData().put(Matrix.DIMENSIONMETADATA + ROW, m.selectRows(Ret.NEW, 0));
} else if (dim == COLUMN) {
MapMatrix<String, Object> a = m.getMetaData();
if (a != null) {
Matrix ai = (Matrix) a.get(Matrix.DIMENSIONMETADATA + ROW);
if (ai != null) {
ai = ai.selectColumns(Ret.NEW, 0);
getMetaData().put(Matrix.DIMENSIONMETADATA + ROW, ai);
}
}
getMetaData().put(Matrix.DIMENSIONMETADATA + COLUMN, m.selectColumns(Ret.NEW, 0));
} else {
throw new RuntimeException("only supported for 2D matrices");
}
}
代码示例来源:origin: ujmp/universal-java-matrix-package
@Test
public void testDeleteRow1And2And3() {
Matrix m = getMatrix();
System.out.println(m);
m = m.deleteRows(Ret.NEW, 1, 2, 3);
System.out.println(m);
assertEquals(2, m.getRowCount());
assertEquals(5, m.getColumnCount());
assertEquals(1, m.getAsLong(0, 0));
assertEquals(1, m.getAsLong(0, 1));
assertEquals(1, m.getAsLong(1, 0));
assertEquals(5, m.getAsLong(1, 1));
}
代码示例来源:origin: ujmp/universal-java-matrix-package
Matrix plt = complete.deleteRows(Ret.NEW, 0);
plt.setColumnLabel(0, "matrix size");
for (int c = 1; c < plt.getColumnCount(); c++) {
代码示例来源:origin: ujmp/universal-java-matrix-package
@Test
public void testDeleteRow0() {
Matrix m = getMatrix();
m = m.deleteRows(Ret.NEW, 0);
assertEquals(4, m.getRowCount());
assertEquals(5, m.getColumnCount());
assertEquals(1, m.getAsLong(0, 0));
assertEquals(2, m.getAsLong(0, 1));
assertEquals(1, m.getAsLong(1, 0));
}
代码示例来源:origin: ujmp/universal-java-matrix-package
@Test
public void testDeleteRow1() {
Matrix m = getMatrix();
m = m.deleteRows(Ret.NEW, 1);
assertEquals(4, m.getRowCount());
assertEquals(5, m.getColumnCount());
assertEquals(1, m.getAsLong(0, 0));
assertEquals(1, m.getAsLong(0, 1));
assertEquals(1, m.getAsLong(1, 0));
assertEquals(3, m.getAsLong(1, 1));
}
代码示例来源:origin: ujmp/universal-java-matrix-package
@Test
public void testDeleteRow1And2() {
Matrix m = getMatrix();
m = m.deleteRows(Ret.NEW, 1, 2);
assertEquals(3, m.getRowCount());
assertEquals(5, m.getColumnCount());
assertEquals(1, m.getAsLong(0, 0));
assertEquals(1, m.getAsLong(0, 1));
assertEquals(1, m.getAsLong(1, 0));
assertEquals(4, m.getAsLong(1, 1));
}
内容来源于网络,如有侵权,请联系作者删除!