1

sorry if this type of question is forbidden but I'm not familiar with the name of the data type I'm trying to achieve...

My code outputs a bunch of appended lists in the form

x = [[1, 2, 3], [2, 2, 2], [1, 4, 4]]

but I want to change the output to be in the form

[[1 2 3]
  2 2 2]
  1 4 4]]

similar to if I drew for example a random 'matrix' (?)

np.random.normal(0,1,size = (3, 3))

I hope someone can give me some advice on what to call these...

Thank you.

EDIT:

I answered my own question, I transferred the list into a numpy array and then reshaped via

shape = (3,3)
y = np.array(x)
y.reshape(shape)
print(y)

[[1 2 3]
 [2 2 2]
 [1 4 4]]
user309575
  • 41
  • 5
  • 2
    The other ouptut list you want is invalid so be clear – Wasif Oct 07 '20 at 09:25
  • This: `[[1 2 3]...` can only be a string. It is not a valid python data structure. You either want a list or an array. You might want to print it in that way. If that is the case, please clarify your question – yatu Oct 07 '20 at 09:31
  • I think I found the answer myself, thanks for pointing me in the right direction :) – user309575 Oct 07 '20 at 09:49
  • 1
    Regarding the edit: the `y.reshape(shape)` line is not necessary and can be safely removed. What will be left is just a conversion of a list of lists to a NumPy array which was covered, for example, here: [List of lists into numpy array](https://stackoverflow.com/q/10346336/7851470). – Georgy Oct 08 '20 at 10:17

0 Answers0