删除一列的numpy数组 [英] Remove one column for a numpy array

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

问题描述

我有一个大小为(48,366,3)的numpy数组,我想从数组中删除最后一列以使其为(48,365,3).最好的方法是什么? (所有条目都是整数.我使用的是Python v2.6)

I have a numpy array of dimension (48, 366, 3) and I want to remove the last column from the array to make it (48, 365, 3). What is the best way to do that? (All the entries are integers. I'm using Python v2.6)

推荐答案

您可以尝试numpy.delete:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html

或者只是获取所需的数组切片并将其写入新数组.

or just get the slice of the array you want and write it to a new array.

例如:

a = np.random.randint(0,2, size=(48,366,3))
b = np.delete(a, np.s_[-1:], axis=1)
print b.shape # <--- (48,365,3)

或等效地:

b = np.delete(a, -1, axis=1)

或:

b = a[:,:-1,:]

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

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