[英]How to get a 3 dimensional array with the first two dimension named
I'm working the numpy librairy in Python 3. I would like to have a 3 dimensionnal array with the first two dimension named.我正在使用 Python 3 中的 numpy 库。我想要一个 3 维数组,其中前两个维度命名。
I have created a 3 dimensionnal array.我创建了一个 3 维数组。 I want to access the array like this
我想像这样访问数组
my_3d_array["dim1_colnameX", "dim2_colnameX", 2:4]
I don't know if this is possible.我不知道这是否可能。
Here's what I've done:这是我所做的:
import numpy as np
my_3d_array = np.zeros((2, 3, 5))
my_dtype = np.dtype(XXXX)
my_3d_array= my_3d_array.dtype(my_dtype)
print(my_3d_array)
Thank you!谢谢!
What do you want your output to look like?您希望您的 output 看起来像什么?
You could transform your array into a pandas Dataframe and name the columns.您可以将数组转换为 pandas Dataframe 并命名列。
Take a look at this , on how to create a dataframe out of a 3d np.array看看这个,关于如何从 3d np.array 创建一个 dataframe
After that you can name and rename the columns like this:之后,您可以像这样命名和重命名列:
#name
df.columns = ['column1', 'column2', 'column3']
#rename
df.rename(columns={'column1': 'dim1_colnameX'}, inplace=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.