Python Forum
variable call back into an array
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable call back into an array
#1
Hello

I would like to get the value of each port area in a pipe in one array. I have developed an array class called Equation where equation.A is an array and equation.c is a vector
I want to assign the value for each area in a different script and then add it to the main program in the array.
so far I have no luck in getting this to work. any help or advice will be appreciated.


This is the main program
import numpy as np
import sys

uCounter = 0

class Pipe(object):
   global uCounter

   def __init__(self, nPorts, volume):
      self.volume = volume
      self.nPorts = nPorts  
      self.freePorts = [] #The ports of the pipe that are not in use 
      self.portSetAreas = []  
      self.portSetAreasValue = [] 
      for i in range(nPorts):
         self.freePorts.append(i)
         self.portSetAreas.append(False)
         self.portSetAreasValue.append(0.0)
      self.Areas = D(self.nPorts)               # where D refers to the domain and how many ports it contain 
      self.pd = np.zeros((self.nPorts))
      self.dt = 0.0  

   def logics(self):
       nFree = len(self.freePorts)
       for port in range(nFree):
          if self.portSetAreas[self.freePorts[port]]:
             self.Areas = self.portSetAreasValue[self.freePorts[port]]  

   def Values1(self):
      equation = Equation(1, uCounter)          #where Equation is an array class 
      for p in range(self.nPorts):              #nPorts is the number of ports with an area 
         equation.A[0, self.m.gid[p]] = self.Areas[p] #the multible values of the Area will be put into an array equation.A
      equation.c[0] = 0.0                       #This is a vector 
      return(equation)

#the problem is with self.Areas[p] this multible values will be called form anoth script "test1"
This is the test1 script
import math
import numpy as np
import sys
import scipy.io
import mainproject

Pipe1.portSetAreas[0] = True
Pipe1.portSetAreasValue[0] = 0.1
Pipe1.portSetAreas[1] = True
Pipe1.portSetAreasValue[1] = 0.1

#0 refer to the inlet of the pipe
#1 refer to the outlet of the pipe
Error:
equation.A[0,self.m.gid[p]] = self.Areas TypeError: float() argument must be a string or a number
Reply


Messages In This Thread
variable call back into an array - by yamifm0f - Jun-06-2019, 01:23 PM
RE: variable call back into an array - by heiner55 - Jun-07-2019, 05:11 AM
RE: variable call back into an array - by yamifm0f - Jun-07-2019, 02:36 PM
RE: variable call back into an array - by heiner55 - Jun-07-2019, 02:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Struggling for the past hour to define function and call it back godlyredwall 2 2,263 Oct-29-2020, 02:45 PM
Last Post: deanhystad
  Simple automated SoapAPI Call with single variable replacement from csv asaxty 1 2,137 Jun-30-2020, 06:38 PM
Last Post: asaxty
  np array tolist and back anthares 2 2,024 Jun-13-2020, 06:58 AM
Last Post: anthares
  Call a variable jmf08 16 5,974 Jan-18-2019, 05:50 AM
Last Post: jmf08
  call a variable from one function to another ... evilcode1 4 4,033 Sep-16-2018, 10:50 AM
Last Post: gruntfutuk
  Spyder hides middle array values in variable explorer window davidqvist 0 2,416 Aug-03-2018, 11:04 AM
Last Post: davidqvist
  How to call a variable declared in a function in another python script lravikumarvsp 2 2,966 Jun-04-2018, 08:45 AM
Last Post: Larz60+
  2D Array/List OR using variables in other variable names? IAMK 4 3,916 Apr-16-2018, 09:09 PM
Last Post: IAMK

Forum Jump:

User Panel Messages

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