Adding a row to matrix with numpy

Needed to convert a one dimensional array to a two dimensional numpy matrix and then add a row vector to the end of the matrix.

import numpy
array1d = range(10,100)
array2d = [array1d[i:i + 10] for i in range(0, len(array1d), 10)]
newline = [88 for i in range(1,11)]
m = numpy.matrix(array2d)
m_extended = numpy.vstack([m, newline])

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.