python es un lenguaje genérico, así que, casi siempre, hay que importar módulos, o bien enteros:
In [1]:
import scipy as np
o bien submódulos:
In [2]:
from matplotlib import pyplot as plt
Para ver los gráficos dentro de la hoja (% es un comando "mágico")
In [3]:
%matplotlib inline
In [37]:
x=np.linspace(1,10,100)
In [38]:
x
Out[38]:
In [6]:
plt.plot(x)
Out[6]:
In [7]:
y=np.cos(x)
In [8]:
plt.plot(x , y )
Out[8]:
In [9]:
x[0]
Out[9]:
In [10]:
y[0]
Out[10]:
Probar: x.[TAB]
In [11]:
x.size
Out[11]:
In [12]:
x[100] # OJO!!!!
In [13]:
x[99]
Out[13]:
In [14]:
x[0:2]
Out[14]:
¡¡ Atención al sangrado !!
In [17]:
for xx in x:
print( xx - 1 )
In [19]:
if x[0] < 1.2 :
print ("Menor que 1.2")
In [21]:
for xx in x:
if xx < 1.2 :
print ( "Menor que 1.2" )
In [39]:
np.savetxt( 'vector.txt' , x )
In [40]:
cc = np.cos( x )
In [42]:
np.savetxt( 'cos.txt' , ( x , cc ) )
In [45]:
np.savetxt( 'cos.txt' , np.transpose(( x , cc )) )
In [47]:
np.savetxt( 'cos.txt' , np.transpose(( x , cc )) , delimiter=',')
In [48]:
np.savetxt( 'cos.txt' , np.transpose(( x , cc )) , delimiter=',' , fmt='%1.4e' )
In [32]:
x = y = z = np.arange(0.0,5.0,1.0)
#np.savetxt('test.out', x, delimiter=',') # X is an array
np.savetxt('test.out', (x,y,z)) # x,y,z equal sized 1D arrays
#np.savetxt('test.out', x, fmt='%1.4e') # use exponential notation
In [50]:
data = np.loadtxt('cos_sin.csv' ) # error !!!!!
In [50]:
data = np.loadtxt('cos_sin.csv' , delimiter=',' )
In [58]:
xx = data[ : , 0 ]
ss = data[ : , 2 ]
In [59]:
plt.plot( xx , ss )
Out[59]: