How can I produce a nice output of a numpy matrix?
I currently have the following snippet:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import numpy
from numpy import linalg
A = [[1,2,47,11],[3,2,8,15],[0,0,3,1],[0,0,8,1]]
S = [[113,49,2,283],[-113,0,3,359],[0,5,0,6],[0,20,0,12]]
A = numpy.matrix(A)
S = numpy.matrix(S)
numpy.set_printoptions(precision=2, suppress=True, linewidth=120)
print("…
Convert pandas dataframe to NumPy array
I am interested in knowing how to convert a pandas dataframe into a NumPy array.
dataframe:
import numpy as np
import pandas as pd
index = [1, 2, 3, 4, 5, 6, 7]
a = [np.nan, np.nan, np.nan, 0.1, 0.1, 0.1, 0.1]
b = [0.2, np.nan, 0.2, 0.2, 0.2, np.nan, np.nan]
c = […