[英]Reshaping Array from 1D to 3D for Keras
I want to reshape my data so that it displays 3 dimensions. 我想重塑数据,使其显示3维。
Here is code to create dummy data: 这是创建伪数据的代码:
Sample = [{'account': 'Jones LLC', 'Jan': 150, 'Label': 0, 'Mar': [[.332, .326], [.058, .138]]},
{'account': 'Alpha Co', 'Jan': 200, 'Label': 0, 'Mar': [[.234, .246], [.013, .592]]},
{'account': 'Blue Inc', 'Jan': 50, 'Label': 1, 'Mar': [[.084, .23], [.745, .923]]}]
df = pd.DataFrame(Sample)
Here is the data visualized: 这是可视化的数据:
df:
account Jan Mar
Jones LLC | 150 | [[.332, .326], [.058, .138]]
Alpha Co | 200 | [[.234, .246], [.234, .395]]
Blue Inc | 50 | [[.084, .23], [.745, .923]]
Now if I type: 现在,如果我输入:
df['Mar'].shape
I get (3,) 我得到(3,)
How can I change this column so that its shape is (3, 2, 2), to represent the data within the arrays? 如何更改此列的形状,使其形状为(3,2,2),以表示数组中的数据?
Thanks!!! 谢谢!!!
np.asarray(df['Mar'].values.tolist())
This has shape (3, 2, 2)
. 这具有形状(3, 2, 2)
。
The problem is because the rows of df['Mar']
are lists and simply using as_matrix()
returns an array of lists. 问题是因为df['Mar']
是列表,并且仅使用as_matrix()
返回列表数组。 Casting everything to a list and then to an array gets everything to np.array
. 将所有内容转换为列表,然后转换为数组,将所有内容转换为np.array
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.