Python Forum
IndexError: invalid index to scalar variable.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndexError: invalid index to scalar variable.
#3
"fitness_function(position)" expects an array (or list or any iterable) of exactly 15 elements. When you do:
fitness_function(particle_position_vector[i])
... you are only passing one element. So I guess you have to pass the whole array, like this:
fitness_function(particle_position_vector)
Note that there have to be 15 elements, so the only correct answer to:
input("Inform the number of particles: ")
... is 15.
Reply


Messages In This Thread
RE: IndexError: invalid index to scalar variable. - by ibreeden - Mar-10-2022, 09:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: index 0 is out of bounds for axis 0 with size 0 atomxkai 2 5,656 Mar-03-2021, 08:26 AM
Last Post: atomxkai
  [split] Getting Index Error - list index out of range krishna 2 2,697 Jan-09-2021, 08:29 AM
Last Post: buran
  IndexError: index 0 is out of bounds for axis 0 with size 0 tmhsa 0 5,389 Apr-24-2020, 10:00 AM
Last Post: tmhsa
  Getting Index Error - list index out of range RahulSingh 2 6,234 Feb-03-2020, 07:17 AM
Last Post: RahulSingh
  pandas.read_sas with chunksize: IndexError list index out of range axelle 0 2,638 Jan-28-2020, 09:30 AM
Last Post: axelle
  IndexError: index out of bounds LeoGER 3 10,767 Sep-05-2019, 02:05 PM
Last Post: LeoGER
  Can you help me with this error? IndexError: invalid index of a 0-dim tensor. DerBerliner 1 4,267 Feb-28-2019, 05:47 PM
Last Post: Larz60+
  Unable to understand reason for error IndexError: tuple index out of range rajat2504 4 54,259 Dec-09-2016, 11:04 AM
Last Post: Kebap

Forum Jump:

User Panel Messages

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