哪个数字表示形状返回的元组中的行和列? [英] Which number represents rows and columns in the tuple returned by shape?

查看:180
本文介绍了哪个数字表示形状返回的元组中的行和列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>> A = np.matrix(np.zeros(2, 3)))  
>>> A.shape  
(2, 3)  
>>> A  
matrix([[ 0.,  0.,  0.],
        [ 0.,  0.,  0.]])

矩阵A包含两行三个零的列还是两列三个零的列吗?

Does the matrix A have two rows with three zeros or two columns with three zeros?

推荐答案

rowscolumns只是我们习惯上为matrix的2维(或更通常是2d numpy)指定的名称大批).

rows, columns are just the names we give, by convention, to the 2 dimensions of a matrix (or more generally a 2d numpy array).

np.matrix是2d,因此此约定很有用.但是np.array可能具有0、1、2或更大的尺寸.为此,这两个名称不太有用.例如,如果1d,它有行还是有列?如果是3d,我们怎么称呼最后一个维度,即深度?还是第一个是页面?

np.matrix is, by definition, 2d, so this convention is useful. But np.array may have 0, 1, 2 or more dimensions. For that these 2 names are less useful. For example if 1d, does it have rows or columns? If 3d, what do we call the last dimension, depth? or maybe the first is pages?

因此,不要过分强调名称.大多数numpy函数会要求您通过数字,0、1、2等(而不是名称)指定轴".

So don't put too much emphasis on the names. Most numpy functions ask you to specify the 'axis', by number, 0, 1, 2 etc., not by name.

如果您从csv文件加载数据并获得dtype字段的一维数组(文件的每一行一个行"),则可能会造成进一步的混乱.字段与列相同吗?有点,但不完全是.

There may be further confusion if you load data from a csv file, and get a 1d array (one 'row' per line of the file) of dtype fields. Are fields the same as columns? Sort of, but not quite.

这篇关于哪个数字表示形状返回的元组中的行和列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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