Java Colt Matrix 包需要帮助

发布于 2024-07-14 05:50:57 字数 105 浏览 7 评论 0原文

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

Can anyone tell me how you can delete columns from a matrix using the Colt library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘逸的'云 2024-07-21 05:50:57

没有明确的方法来删除列,但您可以创建原始矩阵的视图,其中包含除您想要删除的列之外的所有列。

/**
 * 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);
}

There is no explicit method to delete a column, but you can create a view of the original matrix that contains all columns but the one you would like to have removed.

/**
 * 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文