python - 从 np.tril_indices “反转”索引的有效方法
问题描述
np.tril_indices(3)
返回大小为 3 的方阵的下三角索引:
(array([0, 1, 1, 2, 2, 2], dtype=int64),
array([0, 0, 1, 0, 1, 2], dtype=int64))
什么是最有效的方法来代替:
(array([0, 1, 1, 2, 2, 2], dtype=int64),
array([0, 1, 0, 2, 1, 0], dtype=int64))
谢谢。
解决方案
一种方法是
>>> np.subtract.accumulate(np.tril_indices(3), 0)
array([[0, 1, 1, 2, 2, 2],
[0, 1, 0, 2, 1, 0]])
推荐阅读
- r - 如何在r中取消列出dgematrices列表
- angularjs - 尝试使用 Graph api 从 SharePoint Online 库中获取自定义字段的值
- highcharts - Highcharts:赋予系列更新动画与点更新动画相同的平滑度
- sqlite - 关于 SQLite 漏洞?
- php - CURL 超时 - 服务器问题?其他域名 URL 有效
- python - 从具有两个 y 轴的两个数据框创建一个图
- r - 添加新观察并将它们与现有观察相关联
- asp.net-mvc - 如何发布或放入 MVC Web API?到目前为止没有任何效果
- google-apps-script - 在应用脚本代码中的表单响应电子表格中引用列标题文本
- java - 使用 java jdbc 从 Oracle 中的 Clob 字段中获取错误字符