10 Replies - 360 Views - Last Post: 19 March 2012 - 05:37 PM Rate Topic: -----

#1 KevinR2683  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Arrays, just looking for advice.

Posted 19 March 2012 - 08:35 AM

array.get_float_list = [10000000000_12000000000_14000000000_16000000000_18000000000]


    def _get_mhz_list(self, *args, **kwargs):
        rtnLst = []
        myLst = self._get_float_list(*args)
        for each in myLst:
            if each is not None:
                each *= 1000000.0 # multiply by 1 MHz to get base units (Hz)
            rtnLst.append(each)
        return rtnLst



so this is what i have for my array. trying to put values into this. I know i have the code heh but im still new to python just wondering if im doing this right. My question is did I define array.get_float_list correctly with its values or should it be in a differnt format

Is This A Good Question/Topic? 0
  • +

Replies To: Arrays, just looking for advice.

#2 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 09:40 AM

Do you have an object instance called "array"? It should look something like:

class A:
    
    def __init__(self): #The constructor
     self.get_float_list = []

    def _get_float_list(self, *args):
     # A method called from that method you gave

    def _get_mhz_list(self, *args, **kwargs):
     # That method

array = A()
# I am assuming it was meant to be 5 values?
array.get_float_list = [10000000000, 12000000000, 14000000000, 16000000000, 18000000000]



Is this what you can see? I think the array (technically a list) should be comma separated if I understand correctly.

This post has been edited by Simown: 19 March 2012 - 09:40 AM

Was This Post Helpful? 0
  • +
  • -

#3 KevinR2683  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 10:35 AM

MHz = 1000000

def callSignalGenerator (index, s):
    return queryTH( "$driver$SignalGenerator1,%s" % s )

def callPowerMeter( s ):
    return queryTH( "$driver$PowerMeter,%s" % s )


test = "10000 12000 14000"
Frequency = test.split(" ")
i = 0
beginningFreq = 10000
Freq = beginningFreq * MHz
while(Freq < 18000000000):
    Frequency[i].append(Freq) 
    print(Frequency[i])
    Freq = Freq + 2000000000
    i = i + 1
    print(Frequency[i])



beginningFreq = 10000
Frequency = beginningFreq * MHz
while(Frequency < 18000000000):
##    callSignalGenerator("setFrequency,%s" %Frequency)
##    callPowerMeter("setFrequency,%s" %Frequency)
    Frequency = Frequency + 2000000000
    print(Frequency)


##self = "test"
##args = "18000 17000 16000 15000 14000"
##kwargs = 'test'
##
##
##_get_float_list(self, args , kwargs)




after working with a co-worker we came up with the following. Im starting to get python, but to answer your question i believe your correct. When we run the code the only error we get is for the following Frequency[i].append(Freq) Not sure what to do but it works with everything else just not that one piece.
Was This Post Helpful? 0
  • +
  • -

#4 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 10:46 AM

So, you have a list of frequencies:

test = "10000 12000 14000"
Frequency = test.split(" ")


So Frequency is an array/list of strings:
["10000", "12000", "14000"]

To start with i = 0 so:
Frequency[i].append(Freq)

Becomes:
# Frequency[0] = "10000"
"10000".append(Freq) # ERROR


You can't append to the end of a string - it's a list function, are you trying to concatenate with it? Or what are you trying to achieve?
>>> "10000" + "500"
10000500
>>> int("10000") + 500 
10500


This post has been edited by Simown: 19 March 2012 - 10:46 AM

Was This Post Helpful? 0
  • +
  • -

#5 KevinR2683  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 10:54 AM

What i want this program to do is. Have Set values that the array will go though systematiclly so starting at 10GHZ and Moving up by 2Ghz each time till max of 18Ghz. I wanted to store the Values in an Array but i thnk it might be to difficault to do so im probably goning to change it to start at 10Ghz and just add 2Ghz to it each time it goes thru its loop, setting both the SignalGen and Power meter as well. Sorry if im confusing you.. its confusing me just trying to explain it lol.
Was This Post Helpful? 0
  • +
  • -

#6 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 11:03 AM

I don't think it's that hard from what I understand:

values = [10000]
# Since it goes up 4 times
>>> for i in range(4):
       values.append[value[i] + 2000]
       # Set the other values here
>>> values
[10000, 12000, 14000, 16000, 18000]



Something like that?

This post has been edited by Simown: 19 March 2012 - 12:27 PM

Was This Post Helpful? 0
  • +
  • -

#7 KevinR2683  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 01:29 PM

sorry i havent replied .. been working on the code trying to understand it.


GHz = 1000000000

def callSignalGenerator (index, s):
    return queryTH( "$driver$SignalGenerator1,%s" % s )

def callPowerMeter( s ):
    return queryTH( "$driver$PowerMeter,%s" % s )





Values = [10 * GHz]
Freq = Values
while(Freq < 18 * GHz):
	for i in Range(3)
    Values.append[Values[i] + (2 * GHz)] 
    print(Freq[i])
##    callSignalGenerator("setFrequency,%s" %Frequency)
	print(Freq[i])
##    callPowerMeter("setFrequency,%s FR" %Frequency)
	print(Freq[i])
	

##		set values to 10k, range is 3
##    	Values.append[Values[i] + 2000] increments the value 3 times at 2k each time
##     	print(Freq[i])Prints the values



am i closer to understanding.. not really but im getting closer
Was This Post Helpful? 0
  • +
  • -

#8 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 02:11 PM

Well, the code you wrote won't come to an end:

while(Freq < 18 * GHz)



Freq is the assigned to the values list, so it doesn't have a numeric value. Are you trying so see if the last value is > 18GHz? You don't need both a range loop and a while loop. So, I got rid of one:

i = 0
>>> values = [10 * GHz]
>>> while(values[i] < (18 * GHz):
      values.append(values[i] + (2 * GHz))
      // Set the rest of your values
      i += 1
>> values
[10000000000, 12000000000, 14000000000, 16000000000, 18000000000]



Which is what we wanted if GHz = 1000000000?

This post has been edited by Simown: 19 March 2012 - 02:12 PM

Was This Post Helpful? 0
  • +
  • -

#9 KevinR2683  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 03:29 PM

Yup correct. Looks good to me now. Thank you for your help.
Was This Post Helpful? 0
  • +
  • -

#10 KevinR2683  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 12-March 12

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 04:37 PM

I got it to work finally...


GHz = 1000000000
MHz = 1000000
kHz = 1000
 
def callSignalGenerator (index, s):
    return queryTH( "$driver$SignalGenerator1,%s" % s )
 
def callPowerMeter( s ):
    return queryTH( "$driver$PowerMeter,%s" % s )
 
def freq_range(startPoint=0.0, stopPoint=1.0, numPoints=2.0):
    """
    This function returns a list of frequencies specified by start, stop, and 
    the number of elements in the list.

    This function works with ascending or descending values.
    """
    frqLst = []
    if numPoints > 2:
        stepSize = ((stopPoint - startPoint) / (numPoints - 1.0))
        for index in range(numPoints):
            frqLst.append(float(startPoint + (stepSize * index)))
    elif numPoints > 1:
        frqLst.append(startPoint)
        frqLst.append(stopPoint)
    elif numPoints > 0:
        frqLst.append(startPoint)
    return frqLst
 
def freq_list(start=0, stop=1, stepSize=1):
    freqLst = []
    for i in range(((stop - start) / stepSize) + 1):
        freq = (i * stepSize) + start
        freqLst.append(freq)
    return freqLst
	
	
def offset_range(startPoint=0.0, stopPoint=1.0, numPoints=2.0):
    """
    This function returns a list of Offsets specified by start, stop, and 
    the number of elements in the list.

    This function works with ascending or descending values.
    """
    offstLst = []
    if numPoints > 2:
        stepSize = ((stopPoint - startPoint) / (numPoints - 1.0))
        for index in range(numPoints):
            offstLst.append(int(startPoint + (stepSize * index)))
    elif numPoints > 1:
        offstLst.append(startPoint)
        offstLst.append(stopPoint)
    elif numPoints > 0:
        offstLst.append(startPoint)
    return offstLst
 
def offset_list(start=0, stop=1, stepSize=1):
    offsetLst = []
    for i in range(((stop - start) / stepSize) + 1):
        freq = (i * stepSize) + start
        offsetLst.append(offsetLst)
    return offsetLst
 


start = (2 * GHz)
stop = (18 * GHz)
numSteps = ((stop - start) / (1 * GHz)) + 1
freqLst = freq_range(start, stop, numSteps)
print freqLst


##start = (5845 * MHz)
##stop = (6425 * MHz)
##stepSize = (125 * kHz)
##frequencies = freq_list(start, stop, stepSize)
##print frequencies



start = 1
stop = 15
numSteps = ((stop - start) / + 1)
offsetLst = offset_range(start, stop, numSteps)
print offsetLst



Was This Post Helpful? 0
  • +
  • -

#11 Simown  Icon User is offline

  • Blue Sprat
  • member icon

Reputation: 315
  • View blog
  • Posts: 650
  • Joined: 20-May 10

Re: Arrays, just looking for advice.

Posted 19 March 2012 - 05:37 PM

Nice. Good job :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1