python indices_Python numpy.tril_indices_from() 使用实例

本文提供Python代码示例,展示如何使用numpy.tril_indices_from()函数。示例包括创建对称矩阵、处理数据迭代以及读取SLICE输出的三角形矩阵。这些例子强调了该函数在填充和操作矩阵中的应用。
摘要由CSDN通过智能技术生成

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

def get_adjacency_matrix(out_dir, sid, expt_id):

"Returns the adjacency matrix"

vec_path = pjoin(out_dir, sid, '{}_graynet.csv'.format(expt_id))

edge_vec = np.genfromtxt(vec_path)

matrix_size = np.int64( (1.0 + np.sqrt(1.0+8.0*len(edge_vec)))/2.0 )

edge_mat = np.zeros([matrix_size, matrix_size])

# making this symmetric as required by nilearn's plot_connectome (stupid)

# upper tri; diag +1; # lower tri; diag -1

upper_tri = np.triu_indices_from(edge_mat, +1)

lower_tri = np.tril_indices_from(edge_mat, -1)

edge_mat[upper_tri] = edge_vec

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值