首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Java Colt Matrix包需要的帮助

Java Colt Matrix包需要的帮助
EN

Stack Overflow用户
提问于 2009-02-23 23:20:47
回答 1查看 724关注 0票数 0

有人能告诉我如何使用Colt库从矩阵中删除列吗?

EN

回答 1

Stack Overflow用户

发布于 2009-10-02 11:54:10

没有显式的方法来删除列,但您可以创建原始矩阵的视图,该视图包含除要删除的列之外的所有列。

代码语言:javascript
复制
/**
 * Returns a view of the original matrix that contains all rows and all columns
 * except for the specified column.
 *
 * The view is backed by the original matrix, that is, all changes to the
 * returned matrix will be reflected by the original matrix.
 *
 * @param src The matrix to have a column "removed".
 * @param colIdx The index of the column to be hidden
 *        ({@code 0 <= colIdx < src.columns()} .
 * @return A view of the original matrix with column {@code colIdx} removed.
 */
public DoubleMatrix2D hideColumn(final DoubleMatrix2D src, final int colIdx) {
    // create array of column indices to be preserved
    final int[] keepColumns = new int[src.columns() - 1];
    for (int i = 0; i < keepColumns.length; i++) {
        keepColumns[i] = ((i < colIdx) ? i : i + 1);
    }

    return src.viewSelection(null /* keep ALL rows */, keepColumns);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/579832

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档