0 Replies - 1198 Views - Last Post: 05 April 2009 - 10:39 PM Rate Topic: -----

#1 TheBeege   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 40
  • Joined: 01-April 09

Python - Adding corresponding elements of multiple arrays

Post icon  Posted 05 April 2009 - 10:39 PM

Never thought my first question on this forum would be about Python hahaha

First the question, then the context.

How would I go about adding corresponding elements of arrays passed in as a variable length argument list?

Now context and attempted progress:
I've created functions to generate sound waves as raw data, and I'm trying to write a function to combine multiple arrays of said data. It's been quite a trip, since this is the first time I've ever used Python. I tried using a "for in" loop to add each element to each other to create a third array, but it only appended the arrays. Since that version, I've changed my system a bit. I'm working on a function called CombineWaves() that takes in a variable length argument list, but I have no idea how to go about working with an array of arrays in Python.

My original setup worked like this. I had global variables "data" and "cumulativeData". Each wave generator output to "data", then CombineWaves() was called to add the corresponding elements of the arrays.
def CombineWaves(self):
		for i in range(len(self.cumulativeData)):
			self.cumulativeData[i] += self.data[i]

This appended data to cumulativeData. I still have no idea why.

After a few more attempts, I decided that I wanted my CombineWaves() to take in any number of waves. Here is an example of a function call for it.
gen.CombineWaves(gen.GenerateSineWave(3, 800, 25),
				 gen.GenerateSquareWave(3, 800, 50),

I'm thinking that gathering a general understanding of how to work with variable length argument lists to a function would help solve my problem. I've poked around on Google, but a few snippets of code I've seen don't produce as advertised. I'm just sleep deprived and confused X-D

Any and all help is much appreciated ^.^

This post has been edited by TheBeege: 05 April 2009 - 10:39 PM

Is This A Good Question/Topic? 0
  • +

Page 1 of 1