Python Forum
Problem in creating a vector
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem in creating a vector
#8
Okay, after reviewing this for a bit, I believe the data types are changing during the loop, which is the major problem with dynamic data types. The range slices (e.g. list[0:j]) return lists of items or even an empty list. So, I suspect the following:

  1. Iteration 1: self.H_ev_hf_vec contains 2 floats, j = 0. Line 9 above changes self.H_ev_hf_vec to a list of [[], float, [float]].
  2. Iteration 2: self.H_ev_hf_vec contains an empty list, a float, and a list with one float, j = 1. Line 9 above changes self.H_ev_hf_vec to a list of [[[]], float], float, [[float]]].
  3. Etc.

I ran a short test to confirm on my end using the same logic basic logic as your loop:

x = [1,2,3]
for j in range(2):
    print(x)
    x = [x[0:j], x[j] + 5.0 / 2.5, x[j+1:]]

# Output	
[1, 2, 3]
[[], 3.0, [2, 3]]
To verify, add a print() call to print the contents of self.H_ev_hf_vec and self.H_ev_wf_vec.

The loop you have above is infinite because "j=j+1" is on a different indentation level. Also, avoid while loops any time you can; I refactored the while loop into a for loop for you.

self.H_ev_hf_vec = [self.H_ev_ex_l_hf, self.H_ev_su_v_hf]      
self.H_ev_wf_vec = [self.H_ev_su_l_wf, self.H_ev_ex_l_wf, self.H_ev_su_v_wf, self.H_ev_ex_v_wf]      

for j in range(max(len(self.H_ev_hf_vec), len(self.H_ev_wf_vec)) - 2):
    self.Q_ev_hf = self.m_hf * (self.H_ev_hf_vec[j+1] - self.H_ev_hf_vec[j])
    self.Q_ev_wf = self.m_wf * (self.H_ev_wf_vec[j+1] - self.H_ev_wf_vec[j])
    if self.Q_ev_hf > self.Q_ev_wf: 
        self.H_ev_hf_vec = [self.H_ev_hf_vec[0:j], self.H_ev_hf_vec[j] + self.Q_ev_wf / self.m_hf, self.H_ev_hf_vec[j+1:len(self.H_ev_wf_vec)]]
    else:
        self.H_ev_wf_vec = [self.H_ev_wf_vec[0:j], self.H_ev_wf_vec[j] + self.Q_ev_hf / self.m_wf, self.H_ev_wf_vec[j+1:len(self.H_ev_hf_vec)]]
Reply


Messages In This Thread
Problem in creating a vector - by termo - Oct-01-2019, 03:38 PM
RE: Problem in creating a vector - by stullis - Oct-01-2019, 03:45 PM
RE: Problem in creating a vector - by termo - Oct-02-2019, 07:38 AM
RE: Problem in creating a vector - by scidam - Oct-02-2019, 07:53 AM
RE: Problem in creating a vector - by termo - Oct-02-2019, 09:02 AM
RE: Problem in creating a vector - by stullis - Oct-02-2019, 12:45 PM
RE: Problem in creating a vector - by termo - Oct-02-2019, 01:51 PM
RE: Problem in creating a vector - by stullis - Oct-02-2019, 07:33 PM
RE: Problem in creating a vector - by termo - Oct-03-2019, 09:23 AM
RE: Problem in creating a vector - by stullis - Oct-03-2019, 03:03 PM
RE: Problem in creating a vector - by termo - Oct-10-2019, 08:41 AM
RE: Problem in creating a vector - by stullis - Oct-10-2019, 03:09 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a TG crypto Bot_ problem when trying to with bot.polling p1ner0 1 1,539 Apr-27-2022, 03:43 AM
Last Post: p1ner0
Question How to understand the vector/direction mason321 0 1,167 Dec-14-2021, 10:57 PM
Last Post: mason321
  How to find vector of a 3D plot mason321 0 1,060 Nov-13-2021, 05:05 PM
Last Post: mason321
  3D vector class with inheritance from 2D vector class buss0140 4 3,267 Dec-20-2020, 08:44 PM
Last Post: deanhystad
  Problem creating an archive trojantrojan 3 2,205 May-10-2020, 01:32 AM
Last Post: trojantrojan
  Issue with def norm in class Vector DimosG 4 2,581 Mar-26-2020, 05:03 PM
Last Post: DimosG
  Creating Vector from a Program ericvrocha 3 1,983 Oct-08-2019, 07:43 AM
Last Post: newbieAuggie2019
  How to combine two float64 column vector? dsarica 1 2,479 Apr-17-2019, 07:22 PM
Last Post: Yoriz
  Problem while creating an Excel File using python Math_Enthusiast 3 3,272 Dec-09-2017, 08:49 PM
Last Post: buran
  2d vector library advice kristofferorum 1 3,877 Oct-20-2016, 09:09 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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