Merge two numpy arrays Merge two numpy arrays arrays arrays

Merge two numpy arrays


Use np.array and then np.concatenate,

import numpy as npfirst = np.array([[650001.88, 300442.2,   18.73,  0.575,                     650002.094, 300441.668, 18.775],                  [650001.96, 300443.4,   18.7,   0.65,                      650002.571, 300443.182, 18.745],                  [650002.95, 300442.54,  18.82,  0.473,                     650003.056, 300442.085, 18.745]])second = np.array([[1],                   [2],                   [3]])np.concatenate((first, second), axis=1)

Where axis=1 means that we want to concatenate horizontally.

That works for me


Use np.column_stack:

import numpy as npfirst = [[650001.88, 300442.2,   18.73,  0.575,  650002.094, 300441.668, 18.775],         [650001.96, 300443.4,   18.7,   0.65,   650002.571, 300443.182, 18.745],         [650002.95, 300442.54,  18.82,  0.473,  650003.056, 300442.085, 18.745]]second = [[1],          [2],          [3]]np.column_stack([first, second])

If you need it as a list, use the method tolist:

np.column_stack([first, second]).tolist()


Multiply a 5x3 matrix by a 3x2 matrix (real matrix product)

import numpy as npnp_1= np.arange(15).reshape(5,3)np_1