简体   繁体   English

删除python数组中的最后一列

[英]Deleting the last column in a python array

I am trying to build a basic number classifier in python, and I have a 3923 * 65 array. 我正在尝试在python中建立基本的数字分类器,并且我有3923 * 65的数组。 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. 我的数组中的每一行都是一张图像,显示时是从0到9的一个数字。3923 * 64是我的数组的实际大小,最后一列是该图像的实际数字。 I already have an array for the entire 3923 * 65, and one for the 3923 * 64 part of it. 我已经有一个用于整个3923 * 65的数组,以及一个用于3923 * 64部分的数组。 full array: 完整数组:

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

number array: 数字数组:

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]

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. 更改full_array的最后一列与更改last_column相同,因为它们指向内存中的相同数据。

See the Numpy documentation on indexing and slicing for further information. 有关更多信息,请参见有关索引和切片Numpy文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM