zero-tolerance Posted March 1, 2007 Report Share Posted March 1, 2007 Hi everyone. I just have a part of a program that that is written in Python that I don't understnd whats happening. I need to built a LabView code that does just that. I have completed most of the program but this part of it I don't quite understand. I have uploaded this in TXT format so everyone can have a look. The code is not long and probably is not hard to see whats happening but for the moment I haven't got a clue what did the previous person try to do with this part of his python code. My understanding is that he is multiplying 5 with the values [1,2,4,8,16,32,3,6,9,12,24]. Then 2 multiplyed by [1,2,4,8,16,32,3,6,9,12,24] then 3 by [1,2,4,8,16,32,3,6,9,12,24] and finnaly removing any duplicate values that come out. If so, then what is the commented part in BOLD telling: K1 = [i*5 for i in range(20)] # 5, 10 ... 95 K = [] M = [1,2,4,8,16,32,3,6,9,12,24] for j in range(len(M)): for i in range(20): K.append(K1*M[j]*i) Any help is appriciated. Thanks in advanced. Quote Link to comment

PJM_labview Posted March 1, 2007 Report Share Posted March 1, 2007 K1 = [i*5 for i in range(20)] # 5, 10 ... 95 K = [] M = [1,2,4,8,16,32,3,6,9,12,24] for j in range(len (M)): for i in range(20): K.append(K1[i]*M[j]*i) print K I just run the above code snipset in python 2.4 and here is what I got for K [0, 5, 20, 45, 80, 125, 180, 245, 320, 405, 500, 605, 720, 845, 980, 1125, 1280, 1445, 1620, 1805, 0, 10, 40, 90, 160, 250, 360, 490, 640, 810, 1000, 1210, 1440, 1690, 1960, 2250, 2560, 2890, 3240, 3610, 0, 20, 80, 180, 320, 500, 720, 980, 1280, 1620, 2000, 2420, 2880, 3380, 3920, 4500, 5120, 5780, 6480, 7220, 0, 40, 160, 360, 640, 1000, 1440, 1960, 2560, 3240, 4000, 4840, 5760, 6760, 7840, 9000, 10240, 11560, 12960, 14440, 0, 80, 320, 720, 1280, 2000, 2880, 3920, 5120, 6480, 8000, 9680, 11520, 13520, 15680, 18000, 20480, 23120, 25920, 28880, 0, 160, 640, 1440, 2560, 4000, 5760, 7840, 10240, 12960, 16000, 19360, 23040, 27040, 31360, 36000, 40960, 46240, 51840, 57760, 0, 15, 60, 135, 240, 375, 540, 735, 960, 1215, 1500, 1815, 2160, 2535, 2940, 3375, 3840, 4335, 4860, 5415, 0, 30, 120, 270, 480, 750, 1080, 1470, 1920, 2430, 3000, 3630, 4320, 5070, 5880, 6750, 7680, 8670, 9720, 10830, 0, 45, 180, 405, 720, 1125, 1620, 2205, 2880, 3645, 4500, 5445, 6480, 7605, 8820, 10125, 11520, 13005, 14580, 16245, 0, 60, 240, 540, 960, 1500, 2160, 2940, 3840, 4860, 6000, 7260, 8640, 10140, 11760, 13500, 15360, 17340, 19440, 21660, 0, 120, 480, 1080, 1920, 3000, 4320, 5880, 7680, 9720, 12000, 14520, 17280, 20280, 23520, 27000, 30720, 34680, 38880, 43320] Hope it help. PJM Quote Link to comment

B Chavez Posted March 1, 2007 Report Share Posted March 1, 2007 I've attached what I think it should look like in LabVIEW, it gives the same result as what PJM posted. See what you think. http://forums.lavag.org/index.php?act=attach&type=post&id=5067 Quote Link to comment

zero-tolerance Posted March 1, 2007 Author Report Share Posted March 1, 2007 Thats amazing, thank you both, it actualy works. Thanks again. Quote Link to comment

zero-tolerance Posted March 2, 2007 Author Report Share Posted March 2, 2007 Sorry guys but I need some more help. Last night I was trying to do 2 things that I couldn't accomplish AGAIN: 1) From all the numbers that are generated (as above) there are some duplicates. i.e. the integer "0" is repeated a few times etc. And I am trying to remove them since I only need 1 copy of every digit. The problem I am facing here is that the duplicate elements are not next to each other inside the array, for example number appears on index 1 of the array and then the same number on index 30 again etc. 2) Final problem is the averaging. Out of all the numbers I have on the array (i.e. the big list of numbers generated) if I input an array with size 4000, it will go through the list of numbers and the size of the same array on the output should be 3920 on the output. So the last 80 elements of the array are discarded. So, what I am basically trying to do is resize the input array based on the array sizes that are available on the table (i.e. the big list of numbers generated). So the input array was 4000 and the same size is also available on the table, but the next size smaller that 4000 that is available on the table is 3920, so thats the size the input array should choose to take on the output. The above I couln't accomplish all night yesterday, so again any help is appriciated. Thank you in advanced. Quote Link to comment

Mikkel Posted March 2, 2007 Report Share Posted March 2, 2007 QUOTE(zero-tolerance @ Mar 1 2007, 11:48 AM) Sorry guys but I need some more help.Last night I was trying to do 2 things that I couldn't accomplish AGAIN: 1) From all the numbers that are generated (as above) there are some duplicates. i.e. the integer "0" is repeated a few times etc. And I am trying to remove them since I only need 1 copy of every digit. The problem I am facing here is that the duplicate elements are not next to each other inside the array, for example number appears on index 1 of the array and then the same number on index 30 again etc. 2) Final problem is the averaging. Out of all the numbers I have on the array (i.e. the big list of numbers generated) if I input an array with size 4000, it will go through the list of numbers and the size of the same array on the output should be 3920 on the output. So the last 80 elements of the array are discarded. So, what I am basically trying to do is resize the input array based on the array sizes that are available on the table (i.e. the big list of numbers generated). So the input array was 4000 and the same size is also available on the table, but the next size smaller that 4000 that is available on the table is 3920, so thats the size the input array should choose to take on the output. The above I couln't accomplish all night yesterday, so again any help is appriciated. Thank you in advanced. 1) If the order of the elements in the array is not important, you can quite easily find and remove repeated values by first sorting the array ('Sort 1D Array' function). 2) Uhh. Lost me there -Mikkel Quote Link to comment

zero-tolerance Posted March 2, 2007 Author Report Share Posted March 2, 2007 QUOTE(Mikkel @ Mar 1 2007, 07:13 AM) 1) If the order of the elements in the array is not important, you can quite easily find and remove repeated values by first sorting the array ('Sort 1D Array' function). A Very quick and easy solution. Thank you, I never thought of doing it that way. QUOTE(Mikkel @ Mar 1 2007, 07:13 AM) 2) Uhh. Lost me there haha, sorry for bad explanation. The list of numbers shown on the previous post is only a list that decide what should the size of an incomming array be. For example, If I have an array that is of size 80 or 81, as soon as it goes through the list of numbers, the size of This array will be droped down to 60. Because the next smallest number on the list other than 80 is 60, so the size of the array that was at the beginning 80or 81 is droped down to 60. This means that 20 of it elements are deleted. I hope this is a better explanation. Thank you Quote Link to comment

zero-tolerance Posted March 2, 2007 Author Report Share Posted March 2, 2007 I managed to do the program, but I'm not sure if there is a better way of doing it. I have attached the program that does exacly what I need it to do. Any advise is appriciated. Thank you all again for the help. Quote Link to comment

## Recommended Posts

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.