.shape []在"for i in range(Y.shape [0])"中有什么作用? [英] What does .shape[] do in "for i in range(Y.shape[0])"?

查看:1988
本文介绍了.shape []在"for i in range(Y.shape [0])"中有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试逐行细分程序. Y是数据矩阵,但我找不到有关.shape[0]确切功能的任何具体数据.

I'm trying to break down a program line by line. Y is a matrix of data but I can't find any concrete data on what .shape[0] does exactly.

for i in range(Y.shape[0]):
    if Y[i] == -1:

该程序使用numpy,scipy,matplotlib.pyplot和cvxopt.

This program uses numpy, scipy, matplotlib.pyplot, and cvxopt.

推荐答案

numpy数组的shape属性返回数组的尺寸.如果Y具有n行和m列,则Y.shape(n,m).所以Y.shape[0]n.

The shape attribute for numpy arrays returns the dimensions of the array. If Y has n rows and m columns, then Y.shape is (n,m). So Y.shape[0] is n.

In [46]: Y = np.arange(12).reshape(3,4)

In [47]: Y
Out[47]: 
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])

In [48]: Y.shape
Out[48]: (3, 4)

In [49]: Y.shape[0]
Out[49]: 3

这篇关于.shape []在"for i in range(Y.shape [0])"中有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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