python matrix operation with numpy -
i have python array such as:
[[1], [2], [3], [4] ] want make to: [ [1 0 0 0], [2 0 0 0 ], [3 0 0 0], [4 0 0 0] ]
what python way this? suppose use numpy.
create row vector using numpy.eye.
>>> import numpy np >>> = np.array([[1],[2],[3],[4]]) >>> b = np.eye(1, 4) >>> b array([[ 1., 0., 0., 0.]] >>> c = * b >>> c array([[ 1., 0., 0., 0.], [ 2., 0., 0., 0.], [ 3., 0., 0., 0.], [ 4., 0., 0., 0.]])
concatenation of zeros might faster since example uses matrix multiplication achieve required result , not allocation of required size.
Comments
Post a Comment