gpt4 book ai didi

Why can't i change the shape or dimensions of my list?(为什么我不能更改列表的形状或尺寸?)

转载 作者:bug小助手 更新时间:2023-10-25 21:26:27 27 4
gpt4 key购买 nike



target = []
images = []

flattened_data =[]

these are 3 lists I made to append my dataset after the preprocessing, but haven't been able to do so until now because of the difference in the dimensions of these lists and the lists which I want to append into these lists.

这是我制作的3个列表,用于在预处理后附加我的数据集,但由于这些列表的维度和我想要附加到这些列表中的列表的维度不同,直到现在才能做到这一点。


flattened_data = np.array(flattened_data)
flattened_data = flattened_data.reshape(flat.shape)
for category in class_names: # Iterate over the list of category names
for img in os.listdir(path):

np.vstack((flattened_data,flat))

When I try to append using this method this error below is what I get:

当我尝试使用此方法追加时,得到以下错误:


ValueError                                Traceback (most recent call last)
<ipython-input-29-f79792c8d9c0> in <cell line: 2>()
1 flattened_data = np.array(flattened_data)
----> 2 flattened_data = flattened_data.reshape(flat.shape)
3 for category in class_names: # Iterate over the list of category names
4 for img in os.listdir(path):
5

ValueError: cannot reshape array of size 0 into shape (67500,)

Here, flat is the list I get after running the code below.

这里,Flat是我运行下面的代码后得到的列表。


for category in class_names:  # Iterate over the list of category names
for img in os.listdir(path):
img_array = imread(os.path.join(path, img))
img_resized = resize(img_array,(150,150,3))
flat = img_resized.flatten()

Just like this case, I have two more lists which I want to append in target and images respectively but haven't been able to so due to same error, i.e. difference in shape or dimension.

就像这个例子一样,我有另外两个列表,我想分别添加到目标和图像中,但由于相同的错误,即形状或尺寸不同,我无法这样做。


更多回答

@9769953 yes i checked the datatype all the lists I defined myself are lists. I had to to use vstack call because .append() was showing some other errors .that's why I decided to change it to numpy array then use vstack

@9769953是的,我检查了数据类型,我自己定义的所有列表都是列表。我不得不使用vStack调用,因为.append()显示了其他一些错误。

@9769953 Oh sorry, i read it again. are you trying to say that I have to ensure that flattened_data contains the data I want, should make sure that the code responsible for appending data to it is executed as expected ??

#36825;,我又读了一遍。你是想说我必须确保flattened_data包含我想要的数据,应该确保负责向其追加数据的代码按预期执行吗?

i also want to mention that for category in class_names: # Iterate over the list of category names for img in os.listdir(path): img_array = imread(os.path.join(path, img)) img_resized = resize(img_array,(150,150,3)) flat = img_resized.flatten() this code comes before the code below flattened_data = np.array(flattened_data) flattened_data = flattened_data.reshape(flat.shape) for category in class_names: # Iterate over the list of category names for img in os.listdir(path): np.vstack((flattened_data,flat))

我还想提一下,对于CLASS_NAMES中的类别:#迭代os.listdir(路径)中img的类别名称列表:img_array=imread(os.path.Join(Path,img))img_resize=RESIZE(IMG_ARRAY,(150,150,3)Flat=img_sized.Flatten()此代码位于以下代码之前:FLAVEED_DATA=np.array(FLATEED_DATA)FLATEED_DATA=FLATED_DATA。对于CLASS_NAMES中的类别:#迭代os.listdir(路径)中img的类别名称列表:np.vSTACK((FLATED_DATA,FLAT))

well, that is the main problem i haven't been able to add the data I want to add the data I want to add

这就是我一直无法添加我想要添加的数据的主要问题

then what do you suggest other than flattening the image?? (the code you gave is running perfectly, don't know why I was having an error when I was using .append() before)

那么,除了拼合图像之外,您还有什么建议?(您给的代码运行得很好,不知道我之前使用.append()时为什么会出错)

优秀答案推荐

flattened_data = []

for category in class_names: # Iterate over the list of category names
for img in os.listdir(path):
img_array = imread(os.path.join(path, img))
img_resized = resize(img_array,(150,150,3))
flattened_data.append(img_resized.flatten())

flattened_data = np.hstack(flattened_data)
# or
# flattened_data = np.vstack(flattened_data)
# if you want to add it as an extra dimension

更多回答

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com