In [2]:
import numpy as np
import pandas as pd
import math
import cmath
from scipy.optimize import root
from scipy import *
import matplotlib.pyplot as plt
%matplotlib inline

In [62]:
table = ("Tableact6bis.txt")
table


Out[62]:
'Tableact6bis.txt'

In [175]:
class Polynome:
    def __init__(self,table):
        self.table=table
        
    def Lire(self):
        self.abc = pd.read_csv(self.table,sep=" ")
        coef = self.abc.values
        self.a = coef[:,0]
        self.b = coef[:,1]
        self.c = coef[:,2]
        return self.abc 

    def pair_impair(self):
        
        print(self.a)
        print(self.b)
        print(self.c)
        self.liste_pair=list()
        self.liste_impair = list()
        self.vec_abc = vectorize(self.abc)
        print(self.vec_abc)
        
        for self.a2 in self.a:
            if self.a2%2==0:
                self.liste_pair.append(self.a2)
            else:
                self.liste_impair.append(self.a2)
        for self.b2 in self.b:
            if self.b2%2==0:
                self.liste_pair.append(self.b2)
            else:
                self.liste_impair.append(self.b2)
        for self.c2 in self.c:
            if self.c2%2==0:
                self.liste_pair.append(self.c2)
            else:
                self.liste_impair.append(self.c2)
                
        print ("Liste des pairs : {0}".format((self.liste_pair)))
        print ("Liste des impairs : {0}".format((self.liste_impair)))


    
    def calcul(self):
        i = 0
        self.x1 = np.zeros(1)
        self.x2 = np.zeros(1)
        self.x0 = np.zeros(1)
        self.x11 =np.zeros(1)
        self.x12 =np.zeros(1)
                
        for self.a2,self.b2,self.c2 in zip(self.a,self.b,self.c): 
            print("ap : {0},bp : {1} et cp : {2}".format(self.a2,self.b2,self.c2))

            self.Delta = (self.b2**2)-(4 * self.a2 * self.c2)
            print ("Delta = {}".format(self.Delta))
            if self.Delta < 0:
                self.x11 = (-self.b2-cmath.sqrt(self.Delta))/(2*self.a2)
                self.x12 = (-self.b2-cmath.sqrt(self.Delta))/(2*self.a2)
                print ("L'equation a deux solutions : x1 = {0} et x2 ={1}".format(self.x11,self.x12))
            elif self.Delta == 0:
                self.x0 = (-self.b2/(2*self.a2))
                print ("L'equation a une solution: x = {}".format(self.x0))
            else:
                self.x1 = (-self.b2+math.sqrt(self.Delta))/(2*self.a2)
                self.x2 = (-self.b2-math.sqrt(self.Delta))/(2*self.a2)
                print ("L'equation a deux solutions : x1 = {0} et x2 ={1}".format(self.x1,self.x2))
                


    def graphique2(self):
        
        fig,axes=plt.subplots(4,2)
        x = np.linspace(-5,5,100)
        g = (self.a2*x**2)+self.b2*x+self.c2 
    

        for self.a2,self.b2,self.c2 in zip(self.a,self.b,self.c):

            axes[0,0].plot(x,g)
            axes[1,1].plot(x,g)
            axes[0,1].plot(x,g)
            axes[1,0].plot(x,g)

In [176]:
p = Polynome("Tableact6bis.txt")
p


Out[176]:
<__main__.Polynome at 0x1f5ac88b6d8>

In [177]:
p.Lire()


Out[177]:
a b c
0 -4 2 2
1 1 1 1
2 3 3 3
3 4 2 -2
4 1 5 3
5 2 6 -4
6 4 10 -2

In [178]:
p.pair_impair()


[-4  1  3  4  1  2  4]
[ 2  1  3  2  5  6 10]
[ 2  1  3 -2  3 -4 -2]
<numpy.lib.function_base.vectorize object at 0x000001F5ACE25550>
Liste des pairs : [-4, 4, 2, 4, 2, 2, 6, 10, 2, -2, -4, -2]
Liste des impairs : [1, 3, 1, 1, 3, 5, 1, 3, 3]

In [179]:
p.calcul()


ap : -4,bp : 2 et cp : 2
Delta = 36
L'equation a deux solutions : x1 = -0.5 et x2 =1.0
ap : 1,bp : 1 et cp : 1
Delta = -3
L'equation a deux solutions : x1 = (-0.5-0.8660254037844386j) et x2 =(-0.5-0.8660254037844386j)
ap : 3,bp : 3 et cp : 3
Delta = -27
L'equation a deux solutions : x1 = (-0.5-0.8660254037844386j) et x2 =(-0.5-0.8660254037844386j)
ap : 4,bp : 2 et cp : -2
Delta = 36
L'equation a deux solutions : x1 = 0.5 et x2 =-1.0
ap : 1,bp : 5 et cp : 3
Delta = 13
L'equation a deux solutions : x1 = -0.6972243622680054 et x2 =-4.302775637731995
ap : 2,bp : 6 et cp : -4
Delta = 68
L'equation a deux solutions : x1 = 0.5615528128088303 et x2 =-3.5615528128088303
ap : 4,bp : 10 et cp : -2
Delta = 132
L'equation a deux solutions : x1 = 0.18614066163450715 et x2 =-2.686140661634507

In [180]:
p.graphique2()



In [ ]:


In [4]:
X1 = np.ones([10,1])
X1


Out[4]:
array([[ 1.],
       [ 1.],
       [ 1.],
       [ 1.],
       [ 1.],
       [ 1.],
       [ 1.],
       [ 1.],
       [ 1.],
       [ 1.]])

In [6]:
X2 = np.ones([10,1])

In [55]:
A = pd.Series(np.random.randn(10))
A


Out[55]:
0    0.328334
1   -0.607159
2    0.859086
3    0.589051
4   -1.327751
5    0.675124
6    0.186734
7   -0.437258
8   -0.822335
9    0.139260
dtype: float64

In [9]:
A = np.ones([10,1]) * 1.2

In [10]:
- A * X1 ** 2 + 3 * X2


Out[10]:
array([[ 1.8],
       [ 1.8],
       [ 1.8],
       [ 1.8],
       [ 1.8],
       [ 1.8],
       [ 1.8],
       [ 1.8],
       [ 1.8],
       [ 1.8]])

In [ ]:


In [49]:
A = np.random.randint(30.5, size=10)
A = A.T
A


Out[49]:
array([22, 10, 16, 22,  5,  4, 19,  1,  8, 16])

In [41]:
#A =  np.random.random_sample((5,)) * 10
#A

In [52]:
datos = np.array([A.T,A.T])

T1 = pd.DataFrame(data=datos, columns = ["A", "B"])
T1


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/home/andres-python/anaconda3/lib/python3.5/site-packages/pandas/core/internals.py in create_block_manager_from_blocks(blocks, axes)
   4246                 blocks = [make_block(values=blocks[0],
-> 4247                                      placement=slice(0, len(axes[0])))]
   4248 

/home/andres-python/anaconda3/lib/python3.5/site-packages/pandas/core/internals.py in make_block(values, placement, klass, ndim, dtype, fastpath)
   2684 
-> 2685     return klass(values, ndim=ndim, fastpath=fastpath, placement=placement)
   2686 

/home/andres-python/anaconda3/lib/python3.5/site-packages/pandas/core/internals.py in __init__(self, values, placement, ndim, fastpath)
    108                              'implies %d' % (len(self.values),
--> 109                                              len(self.mgr_locs)))
    110 

ValueError: Wrong number of items passed 10, placement implies 2

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-52-9ea82b14fdc9> in <module>()
      1 datos = np.array([A.T,A.T])
      2 
----> 3 T1 = pd.DataFrame(data=datos, columns = ["A", "B"])
      4 T1

/home/andres-python/anaconda3/lib/python3.5/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    295             else:
    296                 mgr = self._init_ndarray(data, index, columns, dtype=dtype,
--> 297                                          copy=copy)
    298         elif isinstance(data, (list, types.GeneratorType)):
    299             if isinstance(data, types.GeneratorType):

/home/andres-python/anaconda3/lib/python3.5/site-packages/pandas/core/frame.py in _init_ndarray(self, values, index, columns, dtype, copy)
    472             values = _possibly_infer_to_datetimelike(values)
    473 
--> 474         return create_block_manager_from_blocks([values], [columns, index])
    475 
    476     @property

/home/andres-python/anaconda3/lib/python3.5/site-packages/pandas/core/internals.py in create_block_manager_from_blocks(blocks, axes)
   4254         blocks = [getattr(b, 'values', b) for b in blocks]
   4255         tot_items = sum(b.shape[0] for b in blocks)
-> 4256         construction_error(tot_items, blocks[0].shape[1:], axes, e)
   4257 
   4258 

/home/andres-python/anaconda3/lib/python3.5/site-packages/pandas/core/internals.py in construction_error(tot_items, block_shape, axes, e)
   4231         raise ValueError("Empty data passed with indices specified.")
   4232     raise ValueError("Shape of passed values is {0}, indices imply {1}".format(
-> 4233         passed, implied))
   4234 
   4235 

ValueError: Shape of passed values is (10, 2), indices imply (2, 2)

In [ ]:


In [57]:
d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
     'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}


d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
     'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
df = pd.DataFrame(d)
df


Out[57]:
one two
a 1.0 1.0
b 2.0 2.0
c 3.0 3.0
d NaN 4.0

In [58]:
df["one"]


Out[58]:
a    1.0
b    2.0
c    3.0
d    NaN
Name: one, dtype: float64

In [ ]:


In [59]:
np.sqrt([4, -1, -3+4J])


Out[59]:
array([ 2.+0.j,  0.+1.j,  1.+2.j])

In [ ]: