numpy_matrix_to_list()

home > kero > Documentation

Convert a numpy matrix to a list.

kero.utils.utils.py

def numpy_matrix_to_list(np_mat):
  return out

Arguments/Return

np_mat Numpy matrix.
Return out List.

Example Usage 1

testUtils3.py

import kero.utils.utils as ut
import numpy as np

n_row = 3
n_col = 2
M = np.random.normal(size=(n_row,n_col))
print(M)
print("------convert to list-----")
out = ut.numpy_matrix_to_list(M)
print(out)
print("------convert back to matrix--------")
MM = np.matrix(out)
print(MM)

The output is the following.

[[-0.07988029  1.2434192 ]
 [-0.5162123  -0.59034063]
 [-1.02402997 -0.74755916]]
------convert to list-----
[[-0.07988028825737249, 1.24341920016077], [-0.5162122966577327, -0.5903406251819941], [-1.024029973127149, -0.7475591629901397]]
------convert back to matrix--------
[[-0.07988029  1.2434192 ]
 [-0.5162123  -0.59034063]
 [-1.02402997 -0.74755916]]

kero version: 0.6.2