提取numpy数组中的特定列 [英] Extracting specific columns in numpy array

查看:1108
本文介绍了提取numpy数组中的特定列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的问题,但请问我有一个MxN矩阵.我要做的就是提取特定的列并将其存储在另一个numpy数组中,但是我得到了无效的语法错误. 这是代码:

This is an easy question but say I have an MxN matrix. All I want to do is extract specific columns and store them in another numpy array but I get invalid syntax errors. Here is the code:

extractedData = data[[:,1],[:,9]]. 

似乎上面的那行就足够了,但我想不是.我环顾四周,但找不到关于此特定情况的任何语法明智的方法.

It seems like the above line should suffice but I guess not. I looked around but couldn't find anything syntax wise regarding this specific scenario.

推荐答案

我假设您想要列19?那是

I assume you wanted columns 1 and 9? That's

data[:, [1, 9]]

或带有名称:

data[:, ['Column Name1','Column Name2']]

您可以从data.dtype.names

这篇关于提取numpy数组中的特定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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