Python Forum
I have a code which is very simple but still I cannot detect what's wrong with it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have a code which is very simple but still I cannot detect what's wrong with it
#1
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
image[i][j] = 1
^
SyntaxError: invalid syntax
Reply
#2
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.
Error:
File "<module4>", line 24 pixel_value = int(np.interp(value, [min(results), max(results)], [0, 255]) ^ SyntaxError: '(' was never closed
Also NumPy dos not support Python 3.7 anymore.
Quote:NumPy stopped supporting Python 3.7 from Dec 26, 2021.
Any older releases (1.20, 1.21) still support Python 3.7.
Releases made after that only support Python 3.8 and above
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with simple code JacobSkinner 1 337 Mar-18-2024, 08:08 PM
Last Post: deanhystad
  Something wrong with my code FabianPruitt 5 869 Jul-03-2023, 10:55 PM
Last Post: Pedroski55
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,586 Mar-27-2023, 07:38 AM
Last Post: buran
  what's wrong? i know this is simple davidorlow 11 1,718 Mar-15-2023, 05:14 PM
Last Post: deanhystad
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,269 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,810 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  help me simple code result min and max number abrahimusmaximus 2 916 Nov-12-2022, 07:52 AM
Last Post: buran
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,576 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Simple encoding code ebolisa 3 1,462 Jun-18-2022, 10:59 AM
Last Post: deanhystad
  How would you (as an python expert) make this code more efficient/simple coder_sw99 3 1,818 Feb-21-2022, 10:52 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020