Python Matrix, rows and columns -


i have problem matrix:

b=   [[-2.5,  0.5],        #b random matrix      [-1.5, -0.5],      [-0.5,  0.5]] 

how can b get:

b=[[[-2.5], [0.5]], [[-1.5], [-0.5]], [[-0.5], [0.5]]] 

many thanks

>>> b=   [[-2.5,  0.5],        #b random matrix      [-1.5, -0.5],      [-0.5,  0.5]] >>> [[[val] val in row] row in b] [[[-2.5], [0.5]], [[-1.5], [-0.5]], [[-0.5], [0.5]]] 

explanation: consider list:

>>> oned = [1, 2, 3] 

you can re-create list comprehension:

>>> [val val in oned]  [1, 2, 3] 

then wrap each element in own list:

>>> [[val] val in oned] [[1], [2], [3]] 

extend 2 dimensions.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -