NumPy: Entrada/Salida

Con E/S (I/O en inglés) entendemos leer y escribir datos archivos. Es algo que necesitaremos hacer con relativa frecuencia, y en NumPy es muy sencillo de hacer. Para el caso de la lectura se usa la función np.loadtxt.

Ejemplo con datos de temperaturas

Para practicar, vamos a leer el archivo temperaturas.csv que contiene datos diarios de temperaturas en Nueva York entre el 1 de enero de 2013 y el 1 de enero de 2014, obtenidos gratuitamente de http://ncdc.noaa.gov/. Como los hemos descargado en formato CSV habrá que tener algunas precauciones a la hora de leer el archivo.


In [1]:
!head ../data/temperaturas.csv  # Esta línea no funciona en Windows


STATION,DATE,TMAX,TMIN
GHCND:USW00094728,20130101,44,-33
GHCND:USW00094728,20130102,6,-56
GHCND:USW00094728,20130103,0,-44
GHCND:USW00094728,20130104,28,-11
GHCND:USW00094728,20130105,56,0
GHCND:USW00094728,20130106,78,11
GHCND:USW00094728,20130107,72,28
GHCND:USW00094728,20130108,89,17
GHCND:USW00094728,20130109,94,39

In [1]:
import numpy as np

In [2]:
%matplotlib inline
import matplotlib.pyplot as plt

In [3]:
datos = np.loadtxt("../data/temperaturas.csv",
                   skiprows=1,  # Saltamos una línea
                   usecols=(1, 2, 3),  # Solo columnas 2, 3 y 4
                   delimiter=',')  # Separados por comas

In [4]:
datos[:9]


Out[4]:
array([[  2.01301010e+07,   4.40000000e+01,  -3.30000000e+01],
       [  2.01301020e+07,   6.00000000e+00,  -5.60000000e+01],
       [  2.01301030e+07,   0.00000000e+00,  -4.40000000e+01],
       [  2.01301040e+07,   2.80000000e+01,  -1.10000000e+01],
       [  2.01301050e+07,   5.60000000e+01,   0.00000000e+00],
       [  2.01301060e+07,   7.80000000e+01,   1.10000000e+01],
       [  2.01301070e+07,   7.20000000e+01,   2.80000000e+01],
       [  2.01301080e+07,   8.90000000e+01,   1.70000000e+01],
       [  2.01301090e+07,   9.40000000e+01,   3.90000000e+01]])

La primera columna es un entero con formato "AAAAMMDD" que vamos a ignorar. Las temperaturas están medidas en décimas de grado Celsius, así que hay que pasarlas a grados Celsius. Vamos a calcular también la temperatura media.


In [5]:
Tmax = datos[:, 1] / 10
Tmin = datos[:, 2] / 10
Tavg = (Tmax + Tmin) / 2

Como vamos a ignorar la columna de las fechas tenemos que crear un dominio para el eje x. Simplemente construiremos un array de enteros desde 0 hasta 365.


In [6]:
x = np.arange(366)

Supongamos que ahora queremos guardar nuestra tabla de datos en un archivo txt, para poder cargarlo ya modificado más adelante. Una manera fácil de hacerlo sería con otra función de NumPy: np.savetxt. Lo usaremos con los argumentos opcionales fmt='%.5f', newline = '\r\n' para obtener un fichero bonito que podamos entender de un vistazo.


In [7]:
matriz_datos = np.zeros([366, 4])
matriz_datos[:, 0] = x
matriz_datos[:, 1] = Tmax
matriz_datos[:, 2] = Tmin
matriz_datos[:, 3] = Tavg

print(matriz_datos[:10])

# np.savetxt('archivo_datos.txt', matriz_datos, fmt='%.5f', newline = '\r\n')


[[ 0.    4.4  -3.3   0.55]
 [ 1.    0.6  -5.6  -2.5 ]
 [ 2.    0.   -4.4  -2.2 ]
 [ 3.    2.8  -1.1   0.85]
 [ 4.    5.6   0.    2.8 ]
 [ 5.    7.8   1.1   4.45]
 [ 6.    7.2   2.8   5.  ]
 [ 7.    8.9   1.7   5.3 ]
 [ 8.    9.4   3.9   6.65]
 [ 9.    8.3   4.4   6.35]]
Ejercicio

Y ahora representamos la evolución de la temperatura media (por ejemplo de color negro), indicando "Daily summaries" en el título, "Days" en el eje x y "Temperature (C)" en el eje y, usando la interfaz orientada a objetos de matplotlib (función plt.subplots). Podemos crear una zona rellena entre la máxima y la mínima con la función fill_between(x, max, min) (por ejemplo de color #4f88b1). Si los límites del eje x no quedan como queremos podemos usar la función set_xlim(xmin, xmax).


In [8]:
import matplotlib.pyplot as plt

In [9]:
fig, ax = plt.subplots()

ax.plot(x, Tavg, 'k')
ax.set_xlim(0, 366)
ax.fill_between(x, Tmin, Tmax, facecolor='#4f88b1', edgecolor='none')
ax.set_title("Resúmenes diarios")
ax.set_xlabel("Días")
ax.set_ylabel("Temperatura (C)")


Out[9]:
<matplotlib.text.Text at 0x9e22b70>

Ejemplo datos calidad del aire


In [10]:
from IPython.display import HTML
HTML('<iframe src="http://www.mambiente.munimadrid.es/sica/scripts/index.php" \
            width="700" height="400"></iframe>')


Out[10]:

Cargando los datos


In [14]:
# Linux command 
!head ../data/barrio_del_pilar-20160322.csv

# Windows
#!gc log.txt | select -first 10 # head


Estación: Barrio del Pilar;;;;

Fecha;Hora;CO;NO2;O3

;;mg/m³;µg/m³;µg/m³

22/03/2016;01:00;0.2;14;73

22/03/2016;02:00;0.2;10;77

22/03/2016;03:00;0.2;9;75

22/03/2016;04:00;0.2;3;81

22/03/2016;05:00;0.2;3;81

22/03/2016;06:00;0.2;6;79

22/03/2016;07:00;0.2;24;59


In [15]:
# loading the data
# ./data/barrio_del_pilar-20160322.csv
data1 = np.genfromtxt('../data/barrio_del_pilar-20160322.csv', skip_header=3, delimiter=';', usecols=(2,3,4))
data1


Out[15]:
array([[   0.2,   14. ,   73. ],
       [   0.2,   10. ,   77. ],
       [   0.2,    9. ,   75. ],
       [   0.2,    3. ,   81. ],
       [   0.2,    3. ,   81. ],
       [   0.2,    6. ,   79. ],
       [   0.2,   24. ,   59. ],
       [   0.3,   48. ,   37. ],
       [   0.3,   40. ,   43. ],
       [   0.3,   41. ,   44. ],
       [   0.3,   20. ,   68. ],
       [   0.3,   17. ,   74. ],
       [   0.2,   14. ,   84. ],
       [   0.3,   16. ,   88. ],
       [   0.3,   15. ,   94. ],
       [   0.4,   29. ,   81. ],
       [   0.3,   23. ,   82. ],
       [   0.3,   26. ,   81. ],
       [   0.3,   30. ,   75. ],
       [   0.4,   57. ,   39. ],
       [   0.4,   73. ,   17. ],
       [   0.4,   51. ,   42. ],
       [   0.4,   72. ,   16. ],
       [   0.4,   61. ,   28. ],
       [   0.3,   25. ,   62. ],
       [   0.3,   21. ,   64. ],
       [   0.3,   40. ,   39. ],
       [   0.4,   52. ,   19. ],
       [   0.4,   47. ,    8. ],
       [   0.4,   42. ,    8. ],
       [   0.5,   68. ,    8. ],
       [   0.6,   71. ,    9. ],
       [   0.9,   76. ,   10. ],
       [   0.7,   63. ,   29. ],
       [   0.3,   27. ,   66. ],
       [   0.3,   13. ,   88. ],
       [   0.2,   10. ,   92. ],
       [   0.3,   10. ,   98. ],
       [   0.3,   11. ,   99. ],
       [   0.3,   12. ,   99. ],
       [   0.2,   11. ,   98. ],
       [   0.2,    8. ,  101. ],
       [   0.2,   13. ,   92. ],
       [   0.2,   23. ,   79. ],
       [   0.5,   40. ,   56. ],
       [   0.6,   49. ,   43. ],
       [   0.5,   66. ,   25. ],
       [   0.4,   47. ,   44. ],
       [   0.3,   18. ,   76. ],
       [   0.3,   25. ,   64. ],
       [   0.3,   16. ,   77. ],
       [   0.3,   16. ,   59. ],
       [   0.3,   34. ,   31. ],
       [   0.3,   27. ,   33. ],
       [   0.3,   44. ,   17. ],
       [   0.4,   45. ,    9. ],
       [   0.5,   52. ,   22. ],
       [   0.4,   37. ,   53. ],
       [   0.3,   21. ,   73. ],
       [   0.3,   20. ,   76. ],
       [   0.3,   24. ,   76. ],
       [   0.4,   38. ,   71. ],
       [   0.3,   32. ,   78. ],
       [   0.3,   21. ,   89. ],
       [   0.2,   10. ,  105. ],
       [   0.3,   15. ,  102. ],
       [   0.3,   21. ,   93. ],
       [   0.3,   45. ,   63. ],
       [   0.4,   59. ,   47. ],
       [   0.4,   59. ,   44. ],
       [   0.7,   99. ,    9. ],
       [   0.6,   88. ,    9. ],
       [   0.8,   93. ,    9. ],
       [   0.9,   89. ,    9. ],
       [   0.8,   84. ,    8. ],
       [   0.5,   64. ,   10. ],
       [   0.4,   58. ,   11. ],
       [   0.5,   53. ,    9. ],
       [   0.4,   41. ,    8. ],
       [   0.5,   43. ,    9. ],
       [   0.5,   45. ,   13. ],
       [   0.6,   51. ,   25. ],
       [   0.5,   44. ,   40. ],
       [   0.4,   36. ,   59. ],
       [   0.4,   36. ,   68. ],
       [   0.3,   26. ,   84. ],
       [   0.3,   16. ,   98. ],
       [   0.3,   17. ,   97. ],
       [   0.3,   24. ,   89. ],
       [   0.3,   17. ,   99. ],
       [   0.3,   12. ,  100. ],
       [   0.3,   42. ,   61. ],
       [   0.4,   52. ,   44. ],
       [   0.5,   54. ,   39. ],
       [   0.5,   60. ,   28. ],
       [   0.6,   73. ,   13. ],
       [   0.5,   58. ,   23. ],
       [   0.4,   58. ,   16. ],
       [   0.5,   61. ,   10. ],
       [   0.5,   59. ,    9. ],
       [   0.4,   50. ,    9. ],
       [   0.3,   31. ,   10. ],
       [   0.4,   36. ,    9. ],
       [   0.6,   45. ,    9. ],
       [   0.5,   43. ,   18. ],
       [   0.5,   37. ,   24. ],
       [   0.5,   40. ,   38. ],
       [   0.4,   26. ,   59. ],
       [   0.3,   14. ,   67. ],
       [   0.3,   12. ,   64. ],
       [   0.3,   13. ,   62. ],
       [   0.2,   10. ,   63. ],
       [   0.2,    7. ,   58. ],
       [   0.2,    8. ,   53. ],
       [   0.2,   11. ,   51. ],
       [   0.3,   16. ,   47. ],
       [   0.2,   19. ,   42. ],
       [   0.3,   22. ,   38. ],
       [   0.3,   23. ,   36. ],
       [   0.3,   16. ,   43. ],
       [   0.2,    9. ,   49. ],
       [   0.2,    6. ,   48. ],
       [   nan,    nan,    nan],
       [   0.2,    4. ,   64. ],
       [   0.2,    3. ,   89. ],
       [   0.2,    4. ,   90. ],
       [   0.2,    3. ,   92. ],
       [   0.2,    6. ,   89. ],
       [   0.3,   11. ,   83. ],
       [   0.3,    9. ,   87. ],
       [   0.3,    8. ,   84. ],
       [   0.3,   10. ,   82. ],
       [   0.3,   10. ,   80. ],
       [   0.3,   12. ,   80. ],
       [   0.3,   12. ,   81. ],
       [   0.3,    8. ,   84. ],
       [   0.3,   10. ,   85. ],
       [   0.2,   10. ,   85. ],
       [   0.2,   14. ,   82. ],
       [   0.3,   18. ,   72. ],
       [   0.3,   28. ,   60. ],
       [   0.3,   30. ,   55. ],
       [   0.3,   21. ,   61. ],
       [   0.3,   16. ,   63. ],
       [   0.3,   12. ,   65. ],
       [   0.2,    9. ,   67. ],
       [   0.2,    5. ,   70. ],
       [   0.2,    5. ,   69. ],
       [   0.2,    6. ,   65. ],
       [   0.2,    7. ,   63. ],
       [   0.3,   16. ,   55. ],
       [   0.3,   30. ,   45. ],
       [   0.3,   38. ,   39. ],
       [   0.3,   37. ,   41. ],
       [   0.3,   29. ,   53. ],
       [   0.3,   27. ,   53. ],
       [   0.3,   27. ,   49. ],
       [   0.3,   23. ,   54. ],
       [   0.3,   22. ,   57. ],
       [   0.3,   19. ,   61. ],
       [   0.3,   17. ,   63. ],
       [   0.3,   22. ,   59. ],
       [   0.3,   27. ,   53. ],
       [   0.3,   29. ,   50. ],
       [   0.3,   34. ,   44. ],
       [   0.3,   33. ,   45. ],
       [   0.3,   26. ,   50. ],
       [   0.3,   19. ,   56. ],
       [   0.2,   11. ,   63. ],
       [   0.2,    8. ,   63. ],
       [   0.2,    9. ,   58. ],
       [   0.2,    6. ,   63. ],
       [   0.2,    5. ,   66. ],
       [   0.2,    7. ,   62. ],
       [   0.3,   18. ,   53. ],
       [   0.4,   38. ,   37. ],
       [   0.4,   49. ,   28. ],
       [   0.4,   45. ,   35. ],
       [   0.3,   34. ,   47. ],
       [   0.3,   24. ,   62. ],
       [   0.3,   24. ,   68. ],
       [   0.3,   28. ,   68. ],
       [   0.3,   23. ,   78. ],
       [   0.3,   21. ,   82. ],
       [   0.3,   17. ,   87. ],
       [   0.3,   23. ,   80. ],
       [   0.3,   28. ,   75. ],
       [   0.3,   29. ,   71. ],
       [   0.3,   46. ,   50. ],
       [   0.4,   66. ,   27. ],
       [   0.3,   51. ,   38. ],
       [   0.3,   42. ,   46. ]])

Valores inexistentes


In [16]:
np.mean(data1, axis=0)


Out[16]:
array([ nan,  nan,  nan])

In [17]:
np.nanmean(data1, axis=0)


Out[17]:
array([  0.33717277,  29.79581152,  55.47643979])

In [18]:
# masking invalid data
data1 = np.ma.masked_invalid(data1)
np.mean(data1, axis=0)


Out[18]:
masked_array(data = [0.3371727748691094 29.79581151832461 55.47643979057592],
             mask = [False False False],
       fill_value = 1e+20)

In [19]:
data2 = np.genfromtxt('../data/barrio_del_pilar-20151222.csv', skip_header=3, delimiter=';', usecols=(2,3,4))
data2 = np.ma.masked_invalid(data2)

Pintando los datos

  • NO2
    • Media anual: 40 µg/m3
    • Media horaria: 200 µg/m3

In [20]:
plt.plot(data1[:, 1], label='2016')
plt.plot(data2[:, 1], label='2015')

plt.legend()

plt.hlines(200, 0, 200, linestyles='--')
plt.ylim(0, 220)


Out[20]:
(0, 220)

In [21]:
from IPython.display import HTML
HTML('<iframe src="http://ccaa.elpais.com/ccaa/2015/12/24/madrid/1450960217_181674.html" width="700" height="400"></iframe>')


Out[21]:
  • CO
    • Máxima diaria de las medias móviles octohorarias: 10 mg/m³

In [22]:
# http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.convolve.html
def moving_average(x, N=8):
    return np.convolve(x, np.ones(N)/N, mode='same')

In [23]:
plt.plot(moving_average(data1[:, 0]), label='2016')

plt.plot(moving_average(data2[:, 0]), label='2015')

plt.hlines(10, 0, 250, linestyles='--')
plt.ylim(0, 11)

plt.legend()


Out[23]:
<matplotlib.legend.Legend at 0xa3c7a20>
  • O3
    • Máxima diaria de las medias móviles octohorarias: 120 µg/m3
    • Umbral de información. 180 µg/m3
    • Media horaria. Umbral de alerta. 240 µg/m3

In [24]:
plt.plot(moving_average(data1[:, 2]), label='2016')
#plt.plot(data1[:, 2])

plt.plot(moving_average(data2[:, 2]), label='2015')
#plt.plot(data2[:, 2])

plt.hlines(180, 0, 250, linestyles='--')
plt.ylim(0, 190)

plt.legend()


Out[24]:
<matplotlib.legend.Legend at 0xa43bd30>

¿Cómo leeríamos un archivo sin usar NumPy?


In [25]:
data_file = '../data/barrio_del_pilar-20151222.csv'

In [26]:
data = []

with open(data_file) as f:
    # Saltamos las tres primeras líneas
    for ii in range(3):
        f.readline()
    
    for line in f:
        line_string = line
        line_list = line.split(';')
        
        date = line_list[0]
        hour = line_list[1]
        
        components_data = []
        for c in line_list[2:]:
            if '-' not in c:
                components_data.append(float(c))
            else:
                components_data.append(np.nan)
        data.append(components_data)
        
print(np.array(data))


[[  5.00000000e-01   6.50000000e+01   7.00000000e+00]
 [  4.00000000e-01   5.00000000e+01   7.00000000e+00]
 [  3.00000000e-01   3.70000000e+01   1.10000000e+01]
 [  3.00000000e-01   3.70000000e+01   1.00000000e+01]
 [  3.00000000e-01   2.90000000e+01   1.70000000e+01]
 [  3.00000000e-01   3.60000000e+01   1.30000000e+01]
 [  3.00000000e-01   4.70000000e+01   7.00000000e+00]
 [  4.00000000e-01   5.70000000e+01   6.00000000e+00]
 [  5.00000000e-01   6.70000000e+01   6.00000000e+00]
 [  5.00000000e-01   6.90000000e+01   8.00000000e+00]
 [  5.00000000e-01   6.70000000e+01   1.10000000e+01]
 [  5.00000000e-01   6.40000000e+01   1.50000000e+01]
 [  5.00000000e-01   6.50000000e+01   2.10000000e+01]
 [  5.00000000e-01   6.80000000e+01   2.40000000e+01]
 [  7.00000000e-01   9.10000000e+01   1.90000000e+01]
 [  8.00000000e-01   1.05000000e+02   1.30000000e+01]
 [  8.00000000e-01   1.02000000e+02   1.00000000e+01]
 [  7.00000000e-01   1.00000000e+02   8.00000000e+00]
 [  1.50000000e+00   1.48000000e+02   7.00000000e+00]
 [  2.70000000e+00   2.23000000e+02   7.00000000e+00]
 [  2.00000000e+00   2.04000000e+02   7.00000000e+00]
 [  3.30000000e+00   2.51000000e+02   7.00000000e+00]
 [  3.00000000e+00   2.64000000e+02   7.00000000e+00]
 [  2.00000000e+00   2.04000000e+02   7.00000000e+00]
 [  1.20000000e+00   1.27000000e+02   6.00000000e+00]
 [  4.00000000e-01   6.10000000e+01   7.00000000e+00]
 [  3.00000000e-01   4.60000000e+01   9.00000000e+00]
 [  3.00000000e-01   4.70000000e+01   7.00000000e+00]
 [  5.00000000e-01   4.40000000e+01   6.00000000e+00]
 [  5.00000000e-01   4.50000000e+01   6.00000000e+00]
 [  5.00000000e-01   4.60000000e+01   6.00000000e+00]
 [  4.00000000e-01   5.30000000e+01   6.00000000e+00]
 [  5.00000000e-01   6.90000000e+01   6.00000000e+00]
 [  9.00000000e-01   9.00000000e+01   7.00000000e+00]
 [  4.00000000e-01   5.10000000e+01   1.10000000e+01]
 [  4.00000000e-01   5.20000000e+01   1.60000000e+01]
 [  4.00000000e-01   5.60000000e+01   2.00000000e+01]
 [  4.00000000e-01   5.90000000e+01   2.70000000e+01]
 [  4.00000000e-01   6.60000000e+01   2.50000000e+01]
 [  6.00000000e-01   7.80000000e+01   2.00000000e+01]
 [  7.00000000e-01   9.60000000e+01   1.10000000e+01]
 [  7.00000000e-01   9.70000000e+01   7.00000000e+00]
 [  1.00000000e+00   1.17000000e+02   7.00000000e+00]
 [  1.70000000e+00   1.58000000e+02   7.00000000e+00]
 [  2.80000000e+00   2.35000000e+02   8.00000000e+00]
 [  3.20000000e+00   2.68000000e+02   7.00000000e+00]
 [  3.40000000e+00   2.81000000e+02   7.00000000e+00]
 [  2.10000000e+00   1.89000000e+02   7.00000000e+00]
 [  7.00000000e-01   8.80000000e+01   6.00000000e+00]
 [  4.00000000e-01   6.60000000e+01   6.00000000e+00]
 [  6.00000000e-01   6.10000000e+01   6.00000000e+00]
 [  6.00000000e-01   5.90000000e+01   6.00000000e+00]
 [  5.00000000e-01   4.50000000e+01   6.00000000e+00]
 [  6.00000000e-01   5.00000000e+01   6.00000000e+00]
 [  7.00000000e-01   5.20000000e+01   6.00000000e+00]
 [  7.00000000e-01   5.10000000e+01   6.00000000e+00]
 [  1.00000000e+00   6.20000000e+01   6.00000000e+00]
 [  9.00000000e-01   6.40000000e+01   6.00000000e+00]
 [  8.00000000e-01   6.80000000e+01   7.00000000e+00]
 [  9.00000000e-01   7.30000000e+01   8.00000000e+00]
 [             nan              nan              nan]
 [  7.00000000e-01   6.90000000e+01   1.40000000e+01]
 [  6.00000000e-01   6.80000000e+01   1.50000000e+01]
 [  7.00000000e-01   7.50000000e+01   1.10000000e+01]
 [  6.00000000e-01   6.70000000e+01   9.00000000e+00]
 [  6.00000000e-01   7.00000000e+01   7.00000000e+00]
 [  9.00000000e-01   8.40000000e+01   7.00000000e+00]
 [  1.00000000e+00   9.20000000e+01   7.00000000e+00]
 [  1.30000000e+00   1.08000000e+02   7.00000000e+00]
 [  1.50000000e+00   1.35000000e+02   7.00000000e+00]
 [  1.20000000e+00   1.16000000e+02   7.00000000e+00]
 [  1.30000000e+00   1.04000000e+02   7.00000000e+00]
 [  1.00000000e+00   8.00000000e+01   7.00000000e+00]
 [  6.00000000e-01   6.30000000e+01   6.00000000e+00]
 [  4.00000000e-01   5.10000000e+01   6.00000000e+00]
 [  4.00000000e-01   4.50000000e+01   6.00000000e+00]
 [  5.00000000e-01   4.60000000e+01   6.00000000e+00]
 [  5.00000000e-01   4.00000000e+01   6.00000000e+00]
 [  6.00000000e-01   3.50000000e+01   6.00000000e+00]
 [  4.00000000e-01   3.90000000e+01   6.00000000e+00]
 [  3.00000000e-01   3.30000000e+01   9.00000000e+00]
 [  3.00000000e-01   2.80000000e+01   1.20000000e+01]
 [  3.00000000e-01   2.10000000e+01   2.20000000e+01]
 [  3.00000000e-01   2.50000000e+01   2.80000000e+01]
 [  3.00000000e-01   2.60000000e+01   3.70000000e+01]
 [  3.00000000e-01   3.20000000e+01   4.20000000e+01]
 [  4.00000000e-01   4.10000000e+01   4.20000000e+01]
 [  5.00000000e-01   5.80000000e+01   3.00000000e+01]
 [  6.00000000e-01   7.20000000e+01   1.70000000e+01]
 [  5.00000000e-01   7.10000000e+01   1.20000000e+01]
 [  1.00000000e+00   1.08000000e+02   7.00000000e+00]
 [  1.70000000e+00   1.65000000e+02   7.00000000e+00]
 [  2.00000000e+00   1.86000000e+02   7.00000000e+00]
 [  2.00000000e+00   1.80000000e+02   7.00000000e+00]
 [  1.80000000e+00   1.78000000e+02   7.00000000e+00]
 [  5.00000000e-01   7.10000000e+01   8.00000000e+00]
 [  4.00000000e-01   4.30000000e+01   1.70000000e+01]
 [  3.00000000e-01   3.60000000e+01   2.20000000e+01]
 [  3.00000000e-01   3.20000000e+01   2.50000000e+01]
 [  3.00000000e-01   2.80000000e+01   2.50000000e+01]
 [  3.00000000e-01   2.30000000e+01   2.90000000e+01]
 [  3.00000000e-01   2.70000000e+01   2.50000000e+01]
 [  4.00000000e-01   3.50000000e+01   1.20000000e+01]
 [  3.00000000e-01   4.10000000e+01   1.00000000e+01]
 [  6.00000000e-01   5.30000000e+01   6.00000000e+00]
 [  9.00000000e-01   6.10000000e+01   6.00000000e+00]
 [  6.00000000e-01   5.80000000e+01   1.10000000e+01]
 [  5.00000000e-01   5.00000000e+01   1.50000000e+01]
 [  5.00000000e-01   5.00000000e+01   2.00000000e+01]
 [  6.00000000e-01   4.90000000e+01   2.30000000e+01]
 [  5.00000000e-01   6.00000000e+01   2.00000000e+01]
 [  6.00000000e-01   6.60000000e+01   1.80000000e+01]
 [  5.00000000e-01   6.40000000e+01   1.90000000e+01]
 [  5.00000000e-01   7.40000000e+01   1.10000000e+01]
 [  8.00000000e-01   1.05000000e+02   7.00000000e+00]
 [  1.50000000e+00   1.54000000e+02   7.00000000e+00]
 [  1.10000000e+00   1.36000000e+02   7.00000000e+00]
 [  6.00000000e-01   8.00000000e+01   7.00000000e+00]
 [  6.00000000e-01   7.40000000e+01   7.00000000e+00]
 [  5.00000000e-01   5.50000000e+01   9.00000000e+00]
 [  4.00000000e-01   4.20000000e+01   1.30000000e+01]
 [  3.00000000e-01   4.10000000e+01   1.40000000e+01]
 [  3.00000000e-01   3.70000000e+01   1.60000000e+01]
 [  3.00000000e-01   3.30000000e+01   1.90000000e+01]
 [  3.00000000e-01   3.20000000e+01   1.90000000e+01]
 [  2.00000000e-01   3.10000000e+01   2.20000000e+01]
 [  3.00000000e-01   2.40000000e+01   3.00000000e+01]
 [  3.00000000e-01   3.50000000e+01   2.10000000e+01]
 [  3.00000000e-01   3.20000000e+01   2.50000000e+01]
 [  4.00000000e-01   3.70000000e+01   2.70000000e+01]
 [  4.00000000e-01   4.20000000e+01   2.30000000e+01]
 [  3.00000000e-01   3.30000000e+01   3.90000000e+01]
 [  3.00000000e-01   2.70000000e+01   5.10000000e+01]
 [  3.00000000e-01   2.50000000e+01   5.40000000e+01]
 [  3.00000000e-01   2.90000000e+01   5.00000000e+01]
 [  3.00000000e-01   3.20000000e+01   4.60000000e+01]
 [  3.00000000e-01   3.00000000e+01   4.90000000e+01]
 [  3.00000000e-01   3.40000000e+01   4.40000000e+01]
 [  4.00000000e-01   5.40000000e+01   2.40000000e+01]
 [  4.00000000e-01   5.40000000e+01   2.30000000e+01]
 [  4.00000000e-01   5.20000000e+01   2.20000000e+01]
 [  4.00000000e-01   5.50000000e+01   2.10000000e+01]
 [  4.00000000e-01   5.50000000e+01   1.90000000e+01]
 [  3.00000000e-01   3.20000000e+01   3.60000000e+01]
 [  3.00000000e-01   2.80000000e+01   3.70000000e+01]
 [  3.00000000e-01   3.60000000e+01   2.70000000e+01]
 [  3.00000000e-01   4.60000000e+01   1.60000000e+01]
 [  3.00000000e-01   3.10000000e+01   2.80000000e+01]
 [  2.00000000e-01   2.90000000e+01   2.90000000e+01]
 [  2.00000000e-01   2.60000000e+01   3.40000000e+01]
 [  3.00000000e-01   3.70000000e+01   2.50000000e+01]
 [  4.00000000e-01   6.20000000e+01   8.00000000e+00]
 [  6.00000000e-01   6.50000000e+01   1.00000000e+01]
 [  4.00000000e-01   6.60000000e+01   1.10000000e+01]
 [  4.00000000e-01   6.00000000e+01   1.70000000e+01]
 [  5.00000000e-01   4.00000000e+01   3.70000000e+01]
 [  4.00000000e-01   5.20000000e+01   3.20000000e+01]
 [  3.00000000e-01   4.20000000e+01   4.30000000e+01]
 [  3.00000000e-01   4.90000000e+01   3.60000000e+01]
 [  4.00000000e-01   5.30000000e+01   2.70000000e+01]
 [  4.00000000e-01   6.10000000e+01   1.40000000e+01]
 [  6.00000000e-01   7.70000000e+01   9.00000000e+00]
 [  5.00000000e-01   7.70000000e+01   8.00000000e+00]
 [  5.00000000e-01   7.60000000e+01   1.00000000e+01]
 [  5.00000000e-01   7.70000000e+01   8.00000000e+00]
 [  4.00000000e-01   6.10000000e+01   1.70000000e+01]
 [  3.00000000e-01   4.80000000e+01   2.50000000e+01]
 [  3.00000000e-01   3.00000000e+01   3.90000000e+01]
 [  2.00000000e-01   1.60000000e+01   4.80000000e+01]
 [  2.00000000e-01   1.10000000e+01   5.30000000e+01]
 [  2.00000000e-01   8.00000000e+00   5.60000000e+01]
 [  2.00000000e-01   7.00000000e+00   5.50000000e+01]
 [  2.00000000e-01   1.00000000e+01   4.90000000e+01]
 [  2.00000000e-01   1.40000000e+01   4.90000000e+01]
 [  3.00000000e-01   3.50000000e+01   2.90000000e+01]
 [  4.00000000e-01   5.10000000e+01   1.50000000e+01]
 [  4.00000000e-01   6.20000000e+01   8.00000000e+00]
 [  5.00000000e-01   6.30000000e+01   9.00000000e+00]
 [  4.00000000e-01   5.00000000e+01   1.60000000e+01]
 [             nan              nan   1.40000000e+01]
 [             nan              nan   1.20000000e+01]
 [  5.00000000e-01   6.00000000e+01              nan]
 [  5.00000000e-01   6.50000000e+01   2.00000000e+01]
 [  5.00000000e-01   6.20000000e+01   2.20000000e+01]
 [  4.00000000e-01   5.10000000e+01   2.70000000e+01]
 [  5.00000000e-01   6.10000000e+01   1.20000000e+01]
 [  5.00000000e-01   6.10000000e+01   1.00000000e+01]
 [  4.00000000e-01   5.40000000e+01   2.00000000e+01]
 [  4.00000000e-01   5.40000000e+01   2.20000000e+01]
 [  3.00000000e-01   4.00000000e+01   3.10000000e+01]
 [  3.00000000e-01   3.00000000e+01   3.80000000e+01]
 [  3.00000000e-01   2.40000000e+01   4.30000000e+01]]

Ya hemos aprendido a efectuar algunas operaciones útiles con NumPy e incluso hemos hecho nuestro primer ejercicio de lectura de datos. Estamos en condiciones de empezar a escribir programas más interesantes, pero aún queda lo mejor.

Si quieres saber más sobre lectura y escritura de ficheros en Python, puedes consultar al documentación oficial:

https://docs.python.org/3.5/tutorial/inputoutput.html#reading-and-writing-files



¡Síguenos en Twitter!



Este notebook ha sido realizado por: Juan Luis Cano, Mabel Delgado y Álex Sáez



<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">Curso AeroPython</span> por <span xmlns:cc="http://creativecommons.org/ns#" property="cc:attributionName">Juan Luis Cano Rodriguez y Alejandro Sáez Mollejo</span> se distribuye bajo una Licencia Creative Commons Atribución 4.0 Internacional.