I have a code which is very simple but still I cannot detect what's wrong with it - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: I have a code which is very simple but still I cannot detect what's wrong with it (/thread-41080.html) |
I have a code which is very simple but still I cannot detect what's wrong with it - max22 - Nov-07-2023 The code is like this and below I'm leaving the error I'm getting in Python (3.7.13): import numpy as np import matplotlib.pyplot as plt # Define the blood test results for four persons person1_results = [80, 90, 100, 110, 120] person2_results = [95, 105, 90, 115, 100] person3_results = [110, 95, 85, 75, 120] person4_results = [75, 80, 85, 90, 95] # Combine the results into a list all_results = [person1_results, person2_results, person3_results, person4_results] # Set image dimensions image_width = len(person1_results) image_height = len(all_results) # Create an array to store pixel values image = np.zeros((image_height, image_width), dtype=np.uint8) # Iterate through each person's results and set pixel values accordingly for i, results in enumerate(all_results): for j, value in enumerate(results): # Map the blood test result to a pixel value (0-255) pixel_value = int(np.interp(value, [min(results), max(results)], [0, 255]) # Set the pixel value in the image image[i][j] = pixel_value # Display the image plt.imshow(image, cmap='gray') plt.title('Blood Test Results') plt.axis('off') plt.show()**THE ERROR I'm GETTING** Quote: File "C:\Users\Hynek\AppData\Local\Temp\ipykernel_8964\4016005249.py", line 26 RE: I have a code which is very simple but still I cannot detect what's wrong with it - snippsat - Nov-07-2023 Line before add ) .pixel_value = int(np.interp(value, [min(results), max(results)], [0, 255])) (Nov-07-2023, 03:22 PM)max22 Wrote: I'm leaving the error I'm getting in Python (3.7.13):You should use a newer Python i would now say Python 3.11 or 3.12. Then would also have gotten a better error message,as error messages has gotten better in newer versions. Also NumPy dos not support Python 3.7 anymore.Quote:NumPy stopped supporting Python 3.7 from Dec 26, 2021. |