带有逗号的Python数组切片? [英] Python Array Slice With Comma?

查看:1356
本文介绍了带有逗号的Python数组切片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道切片Python数组时逗号的用途是什么-我有一个似乎可行的示例,但对我来说看起来很奇怪的行是

I was wondering what the use of the comma was when slicing Python arrays - I have an example that appears to work, but the line that looks weird to me is

p = 20*numpy.log10(numpy.abs(numpy.fft.rfft(data[:2048, 0])))

现在,我知道在对数组进行切片时,第一个数字是开始,第二个是结束,最后一个是步骤,但是在结束号之后的逗号表示什么?谢谢.

Now, I know that when slicing an array, the first number is start, the next is end, and the last is step, but what does the comma after the end number designate? Thanks.

推荐答案

它用于从2D数组中提取特定的.请参见第一个示例此处.

It is being used to extract a specific column from a 2D array. Refer to the first examples here.

因此,您的示例将从前2048行(0到2047)中提取列0(第一列).但是请注意,此语法仅适用于numpy数组,不适用于常规的python列表.

So your example would extract column 0 (the first column) from the first 2048 rows (0 to 2047). Note however that this syntax will only work for numpy arrays and not general python lists.

这篇关于带有逗号的Python数组切片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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