Deleting the last column in a python array

冷暖自知 提交于 2020-12-30 04:49:34

问题


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)

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?


回答1:


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.

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



来源:https://stackoverflow.com/questions/35397580/deleting-the-last-column-in-a-python-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!