列切片和行切片之间是哪一个? [英] Which one is which between column slicing and row slicing?

查看:91
本文介绍了列切片和行切片之间是哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Scipy具有不同类型的矩阵.其中两个是列稀疏矩阵和行稀疏矩阵.列稀疏矩阵支持快速列切片操作,行稀疏矩阵支持快速行切片操作.

Scipy has different kind of matrices. Two of them are the column sparse matrix and the row sparse matrix. The column sparse matrix supports fast column slicing operations and the row sparse matrix supports fast row slicing operations.

但是如果a [i ,:]操作是列或行切片操作,我不是.有帮助吗?

But I am not if the operation a[i,:] is a column or a row slicing operation. Any help?

推荐答案

没有像您自己尝试的一样:

There is nothing like trying it by yourself:

In [1]: import numpy as np

In [2]: np.arange(9).reshape(3,3)
Out[2]: 
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [3]: a = np.arange(9).reshape(3,3)

In [4]: a[0, :]
Out[4]: array([0, 1, 2])

In [5]: a[:, 0]
Out[5]: array([0, 3, 6])

Ergo,第一个索引对应于行,第二个索引对应于列. a[i, :]正在选择行i,因此这是行切片操作.

Ergo, the first index corresponds to the row and the second to the column. a[i, :] is selecting the row i, so it is a row slicing operation.

这篇关于列切片和行切片之间是哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆