Click here to Skip to main content
15,885,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Am running Python 3.8.10 in a 32-bit Windows 7 computer with only 2GB memory and no video card (not even an NVIDIA) - it's a two decade old netbook...

I editd the code below in hopes of finally giving up a result:

Python
import numpy as np
from scipy import ndimage

database = """5 3 4 5 1 2
1 3 1 5 0 4
2 3 0 5 1 2
0 5 4 0 5 2
1 1 0 5 2 4
4 1 4 3 0 0
4 3 3 3 2 3
2 3 3 1 4 1
4 2 3 3 1 1
2 3 1 4 4 2
0 2 3 4 2 2
3 4 5 4 5 1
2 4 3 1 0 2
2 1 2 2 0 5
4 4 1 0 1 3
2 2 5 4 0 2
3 2 2 2 4 3
4 1 3 3 3 2
5 3 3 1 3 5
1 0 2 2 5 3
1 3 3 5 0 2
2 3 4 1 1 0
0 0 4 2 4 1
4 3 2 4 1 3
3 4 4 1 1 4
1 2 4 1 5 4
5 5 4 2 0 5
5 4 1 4 5 5
4 4 4 2 2 0
1 3 1 2 0 1
1 2 4 4 5 5
3 2 1 4 5 5
5 1 5 2 5 4
0 1 5 5 5 4
3 3 1 5 3 5
5 3 3 4 3 5
"""

def predict_next_string(database):
  # Split the database into a list of strings
  strings = np.array(database.split('\n'))

  last_two_strings = ndimage.laplace(strings.astype(bool), mode='constant')


  # Check if there are at least two strings
  if len(last_two_strings) < 2:
      print ("Not enough strings in the database,")
      return

  # Get the second-to-the-last string in the list
  last_string = last_two_strings[-1]

  # Split the last string into a list of integers
  last_string_numbers = [int(x) for x in last_string.split()]

  # Increment each number by one and return the resulting string
  predicted_string = ' '.join([str(x + 1) for x in last_string_numbers])

  print("The predicted next string is", predicted_string)
 
predict_next_string(database)


As usual, it is meant to predict the next string of 6 numbers from 0 to 5.

This time, it showed up an error:

Traceback (most recent call last):
  File "/home/main.py", line 65, in <module>
    predict_next_string(database)
  File "/home/main.py", line 46, in predict_next_string
    last_two_strings = ndimage.laplace(strings.astype(bool), mode='constant')
ValueError: invalid literal for int() with base 10: '5 3 4 5 1 2'


Do I need to add in libraries like pytorch, keras, pandas, etc. to erase the error and finally yield the desired output?
If yes, what rewrites must I insert into the code and where exactly?

What I have tried:

I did some edits (way different from last time)
> had made a function call at the end of the code (thanks to the people who pointed that out)
> put the database portion at the top of the code
...but still an error.
Now am really unsure where to go from here.
Posted
Updated 27-Mar-23 19:36pm
v3
Comments
Richard MacCutchan 28-Mar-23 4:44am    
You are passing a string of numbers to a function that expects either a single number or a list (Not sure which). So go to the documentation for the laplace function to check what it should be.

1 solution

Defining a function in Python doesn't mean it gets executed: you have to call it when you want it to run:
Python
def DoSomething():
   print("Hello World")
Declares a function called DoSomething but you don't get any printout until you add a line to call it:
Python
def DoSomething():
   print("Hello World")
DoSomething()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900