0

Following numpy command:

c = np.matrix('1,0,0,0;0,1,0,0;0,0,1,0;-6.6,1.0,-2.8, 1.0')

creates a matrix Outupt:

[[ 1.   0.   0.   0. ]
 [ 0.   1.   0.   0. ]
 [ 0.   0.   1.   0. ]
 [-6.6  1.  -2.8  1. ]]

However my Input is a comma-separated array of floats :

[1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -6.604560409595856, 1.0, -2.81542864114781, 1.0]

Is there a simple way of getting those floats, easily into a numpy matrix by defining the shape in before as a 4 x 4 matrix?

user1767754
  • 23,311
  • 18
  • 141
  • 164

1 Answers1

1
np.array([1.0, 0.0,..., -2.81542864114781, 1.0]).reshape((4, 4))
U2EF1
  • 12,907
  • 3
  • 35
  • 37
  • thats the right answer! thanks, is an array considered the same as a matrix and vice versa? – user1767754 Aug 13 '15 at 18:06
  • 1
    @user1767754 Matrices are 2d only and use "matrix multiplication" for `a * b`. And there are [some other differences](http://stackoverflow.com/a/4151251/507762). I would try to stick strictly to one or the other where possible. – U2EF1 Aug 15 '15 at 05:59