X[:,0]内逗号的含义

2024-10-01 09:35:11 发布

您现在位置:Python中文网/ 问答频道 /正文

如果X是一个数组,X[:,0]是什么意思?事实上,这不是我第一次看到这样的事情,它让我困惑,但我不明白它的意思是什么?谁能给我举个例子吗?在逗号这个问题上,如果能有一个完整明确的答案,我将不胜感激。在

请参阅文件https://github.com/lazyprogrammer/machine_learning_examples/blob/master/ann_class/forwardprop.py

提前谢谢!在


Tags: 文件答案httpsgithubcom请参阅数组machine
3条回答

我正在创建一个示例矩阵:

import numpy as np
np.random.seed(0)  
F = np.random.randint(2,5, size=(3, 4), dtype = 'int32' )
F

enter image description here

查询切割矩阵行:

^{pr2}$

enter image description here

查询切割矩阵列:

F[:,2]

enter image description here

>>> x = [1, 2, 3]
>>> x[:, 0] Traceback (most recent call last):
    File "<stdin>", line 1, in <module>  TypeError: list indices must be integers, not tuple

如果您看到了这一点,那么变量不是一个list,而是其他东西。也许是一个纽比阵列。在

砖块中的逗号将行与要从数组中滑出的列分隔开。在

x[row,column]

您可以在行和列值之前或之后放置“:”。在值之前表示“unitl”,在值之后表示“from”。在

例如,您有:

^{pr2}$

相关问题 更多 >