本文介绍了将 python 中的数据帧重塑为 3D的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将手写字符数据集重塑为 3D 形式,以便它可以与数字识别数据集连接.我尝试了很多次,但我无法弄清楚如何做到这一点.

I am trying to reshape a handwritten character dataset into 3D form so that it can be concatenated with digit recognition dataset. I tried multiple times, but I couldnt figure out how it can be done.

实际数字识别数据集的形状为 (60000, 28, 28)字符识别数据集的形状为 (372450, 785),第一列是目标变量.由于排除第一列 28*28=784,因此有可能将其转换为与数字数据集相同的 3D.请就如何做到这一点提出建议?

The actual digit recognition dataset has the shape (60000, 28, 28)The character recognition dataset has the shape (372450, 785) and the first column is target variable. Since excluding first column 28*28=784 there is a possibility that it can be converted to 3D same as digit dataset. Please advice on how this can be done?

对于整个数据框,我需要像 (372450,28,28) 这样的形状

I need a shape like (372450,28,28) for the entire dataframe

提前致谢

推荐答案

形状数组 (372450, 785) 不能被做成 (372450,28,28) 因为 28*28 是 784 而不是 785.但是如果你的意思是将 (372450, 784) 变成 (372450,28,28),你可以这样做

An array of shape (372450, 785) cannot be made into (372450,28,28) because 28*28 is 784 not 785. But if you meant making a (372450, 784) into (372450,28,28), you could do

arr = df.column_name.values 

将从数据框 dfcolumn_name 字段中给出一个 numpy 值数组.

will give a numpy array of values from the column_name field of the data frame df.

现在你可以像使用 reshape() 一样

Now you can use reshape() like

arr = arr.reshape(-1,28,28)

现在 arr 将是形状 (372450,28,28).

Now arr will be of shape (372450,28,28).

这篇关于将 python 中的数据帧重塑为 3D的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 10:54