'Expected 1D or 2D array, got 3D array instead, please how can i solve it?
Please here is my code
mask = np.reshape(binarized_predict_masks[j], newshape=(input_img_size, input_img_size))
resized_mask = Image.fromarray(mask).resize((size, size))
resized_mask = np.asarray(resized_mask)
cropped_resized_mask = resized_mask[((size-w)//2):((size-w)//2 + w), ((size-h)//2):((size-h)//2 + h)]
cropped_resized_mask = np.reshape(cropped_resized_mask, newshape=(w, h, 1))
predicted_mask_path = img_path.replace('original_2D', 'mask_original_2D', 2)
# save txt file
predicted_mask_txt_path = predicted_mask_path.replace('.png', '.txt', 1)
np.savetxt(predicted_mask_txt_path, cropped_resized_mask, fmt='%.6f')
after execution, I receive the error: ValueError: Expected 1D or 2D array, got 3D array at #save txt file
I know that np.save txt only works for 1D and 2D arrays but I don't know how in view of this I should modify this box of code so that it works. Please help me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
