Python Arrays of Tuples

arraysfor-loopnumpypythontuples

I'm trying to write a for loop in python to create an array of tuples that should look like

Output = [(0.0,C[0]),(0.0,C[1]),(0.0,C[2]), .... , (0.0,C[n-1])]

where C is an array of some other numbers.

If I try (something that would work with matlab)

for n in xrange(0,N):
    Output[n]=numpy.asarray( [0.0,C[n]] )

then I get the error ValueError: setting an array element with a sequence.

Could anyone help?

Best Answer

numpy.array([(0.0, C[x]) for x in range(n)])