Sunday 5 July 2009

Append column or array to numpy array

Troubles remembering this, as it is not a part of the array object, but a numpy function. Anyway, to append a column:

Make sure the array is two dimensional and of expected form:

a = a.reshape(len(a), 1)
b = numpy.append(a, a, axis = 1)

or, if the column to be added is currently looking row-like:

b = numpy.append(a, c.transpose(), axis = 1)


To append a row:
b = numpy.append(a, a, axis = 0)

No comments:

Post a Comment