Python Forum
Need help fixing Index Error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help fixing Index Error
#2
This returns the same error.
import numpy as np
x = np.array((1, 2, 3))
y = x[1]
z = y[1]
Error:
File "test.py", line 4, in <module> z = y[1] IndexError: invalid index to scalar variable.
This indicates that something that is not indexable is being indexed. In particular it means a numpy scalar is being indexed because you get a different error message if you index an int or a float.

But I don't see where this is happening in your code. I did this as a quick check.
import numpy as np

iteration = 40
Ltotal = np.linspace(1,20000,iteration) #m
m = np.linspace(1,40,iteration) #number of passes
ktube = np.array([400,48,160,16]) #copper,mild steel, aluminum, stainless steel
Cptube = np.array([376.8,510.8,921.1,460.5])
ptube = np.array([894,785,270,800] )
tfin = np.linspace(0.1/1000,1/1000,iteration) #m
tspace = np.linspace(1/1000,1/100,iteration) #m
ODtube = np.linspace(0.0001,1,iteration) #m
unitcost = np.array([7.50,0.34,1.87,1.98]) #$/kg

i = 0
j = 0
print(Ltotal[i],m[i],ktube[j],Cptube[j],ptube[j],tfin[i],tspace[i],ODtube[i],unitcost[j])
That ran with no problems, leaving this:
values(Ltotal[i],m[i],ktube[j],Cptube[j],ptube[j],tfin[i],tspace[i],ODtube[i],unitcost[j])
What is values()?
Reply


Messages In This Thread
Need help fixing Index Error - by adesimone - Nov-21-2022, 05:17 PM
RE: Need help fixing Index Error - by deanhystad - Nov-21-2022, 07:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  fixing error TypeError: 'float' object is not subscriptable programmingirl 1 1,557 Jan-28-2023, 08:13 PM
Last Post: deanhystad
  how do I fix an index error? MehHz2526 1 1,262 Jan-15-2023, 08:23 PM
Last Post: Gribouillis
  could somebody tell me how I fix an index error? MehHz2526 3 1,381 Nov-29-2022, 07:47 AM
Last Post: buran
  Fixing my backup function Beginner_coder123 4 3,086 Jun-15-2019, 07:56 PM
Last Post: Beginner_coder123
  Fixing arrays output in Python WLST script pkbash 2 4,041 Feb-28-2019, 06:20 PM
Last Post: pkbash
  Need help with fixing iteration counter Kapolt 8 4,780 Oct-18-2018, 07:56 PM
Last Post: buran
  i need help in fixing my scientific calculator coding : (, im using python 3.5.5 hans77 1 4,198 Oct-17-2018, 03:26 AM
Last Post: stullis

Forum Jump:

User Panel Messages

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