删除python数组中的最后一列 [英] Deleting the last column in a python array

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

问题描述

我正在尝试用 python 构建一个基本的数字分类器,我有一个 3923 * 65 的数组.我的数组中的每一行都是一个图像,显示时是一个从 0 到 9 的数字.3923 * 64 是我的数组的实际大小,最后一列是图像的实际数字.我已经有一个用于整个 3923 * 65 的数组,还有一个用于 3923 * 64 部分的数组.完整数组:

I am trying to build a basic number classifier in python, and I have a 3923 * 65 array. Each row in my array is an image that when showed is a number from 0 to 9. 3923 * 64 is the actual size of my array, and the last column is the actual number the image is. I already have an array for the entire 3923 * 65, and one for the 3923 * 64 part of it. full array:

fullImageArray = np.zeros((len(myImageList),65), dtype = np.float64)
fullImageArray = np.array(myImageList)

数字数组:

fullPlotArray = np.zeros((len(myImageList),64), dtype = np.float64)
fullPlotArray = np.array(fullImageArray)
fullPlotArray.resize(len(myImageList),64)

如何制作仅包含最后一列的数组?

How do I make an array of only the last column?

推荐答案

您可以通过对数组进行切片来创建数据视图:

You can create views of your data by slicing the array:

full_array = np.array(myImageList)
plot_array = full_array[:, :64]  # First 64 columns of full_array
last_column = full_array[:, -1]

结果将是与原始数组相同的数据;没有创建副本.更改full_array 的最后一列与更改last_column 相同,因为它们指向内存中的相同数据.

The results will be views into the same data as the original array; no copy is created. changing the last column of full_array is the same as changing last_column, since they are pointing to the same data in memory.

请参阅 关于索引和切片的 Numpy 文档 以了解更多信息信息.

See the Numpy documentation on indexing and slicing for further information.

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

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