INTRODUCCIÓN A R Y PYTHON

Author

CRISTHIAN OMAR PALOMINO MORALES

Introducción a R y Python

HISTORIA Y ORÍGENES

R

  • R es un lenguaje de alto nivel para análisis estadístico y computación de datos.

  • R fue desarrollado por Ross Ihaka y Robert Gentleman y se basa en el lenguaje S de Bell Labs (John Chambers).

  • Lugar: Universidad de Auckland, Nueva Zelanda

  • Motivo: S-PLUS muy costoso ($50,000 USD)

  • Liberación: 1995 bajo licencia GPL

  • CRAN (Comprehensive R Archive Network) 1997 (Kurt Hornik) : En términos simples, CRAN es el repositorio oficial y centralizado de paquetes para el lenguaje de programación R. Es el lugar de donde R y sus usuarios obtienen software, paquetes y documentación.

Python

  • Creador: Guido van Rossum (1989)

  • Lugar: CWI Amsterdam (Centro de Matemáticas e Informática)

  • Inspiración: Lenguaje ABC + Monty Python

  • Filosofía: “Zen de Python” (PEP 20)

CARACTERÍSTICAS TÉCNICAS

R - Fortalezas Estadísticas

  • Valores faltantes (NA) especializados

  • Factores para variables categóricas

  • Vectorización automática

  • Sintaxis de fórmulas estadísticas

  • Gráficos de calidad de publicación (ggplot2, lattice)

  • 18,500+ paquetes especializados en CRAN

Python - Versatilidad General

  • Propósito general (no solo estadística)

  • Sintaxis simple y legible

  • Indentación obligatoria

  • Librería estándar extensa (“batteries included”)

  • Dominio en ML/AI (80% de producción)

DOMINIOS DE APLICACIÓN

R (Excelencia en)

  • Investigación biomédica (FDA aprobado)

  • Finanzas y econometría avanzada

  • Ciencias sociales (psicometría, modelos multinivel)

  • Análisis exploratorio y visualización

  • Investigación académica

Python (Liderazgo en)

  • Machine Learning (scikit-learn, TensorFlow, PyTorch)

  • Desarrollo web (Django, Flask)

  • Automatización y scripts

  • APIs e integración de sistemas

  • Producción y despliegue

Comparación: R vs Python

¿Cuándo usar cada uno?

R es mejor para:- Estadística avanzada - Visualización de datos - Investigación académica - Análisis exploratorio

Python es mejor para:- Machine Learning - Producción/APIs - Automatización Integración de sistemas

¿Qué es una IDE?

Un IDE (Integrated Development Environment - Entorno de Desarrollo Integrado) es un software especializado que combina todas las herramientas necesarias para programar en una sola interfaz.

Analogía: Si programar fuera como construir una casa:

  • Editor de texto = Martillo y herramientas básicas

  • IDE = Taller completo con todas las herramientas organizadas

Características principales de un IDE

1. Editor de código inteligente

  • Resaltado de sintaxis por colores

  • Autocompletado automático

  • Indentación automática

  • Plegado de código (fold/unfold)

2. Depurador (Debugger)

  • Puntos de interrupción (breakpoints)

  • Ejecución paso a paso

  • Inspección de variables

  • Seguimiento de errores

3. Compilador/Intérprete integrado

  • Ejecución directa del código

  • Visualización de resultados

  • Consola integrada

4. Gestión de proyectos

  • Organización de archivos

  • Navegación entre archivos

  • Búsqueda en todo el proyecto

5. Integración con herramientas

  • Control de versiones (Git)

  • Terminal integrada

  • Gestión de paquetes/librerías

6. Personalización

  • Temas de colores

  • Atajos de teclado configurables

  • Extensiones y plugins

Algunos comandos para revisar la version de R y Python en la que estamos trabajando

R.version.string
[1] "R version 4.5.1 (2025-06-13 ucrt)"
R.version
               _                                
platform       x86_64-w64-mingw32               
arch           x86_64                           
os             mingw32                          
crt            ucrt                             
system         x86_64, mingw32                  
status                                          
major          4                                
minor          5.1                              
year           2025                             
month          06                               
day            13                               
svn rev        88306                            
language       R                                
version.string R version 4.5.1 (2025-06-13 ucrt)
nickname       Great Square Root                
#Personalizar prompt
#| options(prompt = "R> "
#| options(continue = "+ ")
import sys
print(sys.version)
3.11.13 (main, Jul 11 2025, 22:36:59) [MSC v.1944 64 bit (AMD64)]

1. Operaciones aritméticas básicas

1.1. Operaciones fundamentales

2 + 3    # Suma: 5
[1] 5
14/6     # División: 2.333333
[1] 2.333333
3^2      # Potenciación: 9
[1] 9
2**3     # Potenciación alternativa: 8
[1] 8
2 + 3    # Suma: 5
5
14/6     # División: 2.3333333333333335
2.3333333333333335
3**2     # Potenciación: 9
9
2**3     # Potenciación: 8
8

1.2. Operaciones avanzadas

17 %% 5     # Módulo: 2 (es decir el resto de la división)
[1] 2
17 %/% 5    # División entera: 3 (es decir la parte entera de la división)
[1] 3
sqrt(9)     # Raíz cuadrada: 3
[1] 3
abs(-5)     # Valor absoluto: 5
[1] 5
17 % 5      # Módulo: 2
2
17 // 5     # División entera: 3
3
#Para algunas funciones en python como la raiz necesitamos importar la libreria math.
import math
math.sqrt(9) # Raíz cuadrada: 3.0
3.0
abs(-5)     # Valor absoluto: 5
5

1.3. Funciones matemáticas

sin(pi/2)       # Seno: 1
[1] 1
log(10)         # Log natural: 2.302585
[1] 2.302585
log10(100)      # Log base 10: 2
[1] 2
exp(1)          # Exponencial: 2.718282
[1] 2.718282
round(pi, 4)    # Redondeo: 3.1416
[1] 3.1416
import math

math.sin(math.pi/2)    # Seno: 1.0
1.0
math.log(10)           # Log natural: 2.302585092994046
2.302585092994046
math.log10(100)        # Log base 10: 2.0
2.0
math.exp(1)            # Exponencial: 2.718281828459045
2.718281828459045
round(math.pi, 4)      # Redondeo: 3.1416
3.1416

2. Asignación de variables

2.1. Métodos de asignación

x <- 5        # Asignación estándar
y = 10        # Asignación con =
15 -> z       # Asignación hacia derecha
(resultado <- 2 + 3) # Asignación con impresión: 5 (los parentesis ejecutan el print)
[1] 5
x = 5         # Asignación estándar
y = 10        # Asignación con =
# No hay asignación hacia derecha
resultado = 2 + 3
print(resultado) # 5
5

2.2. Reglas de nomenclatura

R:

  • Comienzan con letra o punto

  • Pueden contener letras, números, puntos y guiones bajos

  • Sensible a mayúsculas

Python:

  • Comienzan con letra o guión bajo

  • Pueden contener letras, números y guiones bajos

  • Sensible a mayúsculas

2.3. Palabras reservadas

No podrás usar como nombre de la variable a las siguientes palabras:

R: TRUE, FALSE, NULL, Inf, NaN, NA, if, else, function, for, etc.
Python: True, False, None, if, else, def, for, while, etc.

3. Gestión del Espacio de Trabajo

3.1. Listar y eliminar objetos

ls()                    # Listar objetos
[1] "resultado" "x"         "y"         "z"        
ls(pattern = "var")     # Listar con patrón
character(0)
rm(x, y)                # Eliminar objetos
rm(list = ls())         # Eliminar todos
dir()                   # Listar objetos (incluye built-ins)
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'math', 'r', 'resultado', 'sys', 'x', 'y']
globals().keys()        # Listar variables globales
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__annotations__', '__builtins__', 'r', 'sys', 'math', 'x', 'y', 'resultado'])
del x, y                # Eliminar objetos
# No hay equivalente directo para eliminar todos

3.2. Guardar y cargar espacio

save.image("mi_sesion.RData")
load("mi_sesion.RData")

4. Tipo de datos atómicos

4.1. Númericos

x <- 5          # numeric/double
class(x)        # "numeric"
[1] "numeric"
typeof(x)       # "double"
[1] "double"
y <- 10L        # integer
class(y)        # "integer"
[1] "integer"
x = 5           # int
type(x)         # <class 'int'>
<class 'int'>
y = 10.0        # float
type(y)         # <class 'float'>
<class 'float'>

4.2. Cadenas de texto

nombre <- "Juan"
nchar(nombre)   # 4
[1] 4
paste(nombre, "Pérez") # "Juan Pérez"
[1] "Juan Pérez"
nombre = "Juan"
len(nombre)     # 4
4
nombre + " Pérez" # "Juan Pérez"
'Juan Pérez'

4.3. Lógicos

verdadero <- TRUE
falso <- FALSE
TRUE + FALSE    # 1 (coerción numérica)
[1] 1
verdadero = True
falso = False
int(True) + int(False) # 1 (necesita conversión explícita)
1

4.4. Complejos

z1 <- 3 + 4i
Re(z1)          # Parte real: 3
[1] 3
Im(z1)          # Parte imaginaria: 4
[1] 4
z1 = 3 + 4j
z1.real         # Parte real: 3.0
3.0
z1.imag         # Parte imaginaria: 4.0
4.0

5. Vectores

5.1. Creación de vectores

(numeros <- c(1, 3, 5, 7, 9))           # Vector numérico
[1] 1 3 5 7 9
(colores <- c("rojo", "verde", "azul")) # Vector de caracteres
[1] "rojo"  "verde" "azul" 
1:10                                   # Secuencia: 1 2 3 ... 10
 [1]  1  2  3  4  5  6  7  8  9 10
seq(0, 1, 0.2)                         # Secuencia flexible: 0.0 0.2 0.4 0.6 0.8 1.0
[1] 0.0 0.2 0.4 0.6 0.8 1.0
rep(5, 4)                              # Repetición: 5 5 5 5
[1] 5 5 5 5
#Para el uso de vectores en Python requerimos la libreria de numpy
import numpy as np

numeros = np.array([1, 3, 5, 7, 9])    # Array numérico
colores = ["rojo", "verde", "azul"]    # Lista de strings
list(range(1, 11))                     # Secuencia: [1, 2, 3, ..., 10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
np.arange(0, 1.1, 0.2)                 # Secuencia flexible: [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]
array([0. , 0.2, 0.4, 0.6, 0.8, 1. ])
np.repeat(5, 4)                        # Repetición: [5, 5, 5, 5]
array([5, 5, 5, 5])

5.2. Propiedades de vectores

(numeros <- c(1, 3, 5, 7, 9)) 
[1] 1 3 5 7 9
length(numeros)    # Longitud: 5
[1] 5
class(numeros)     # Clase: "numeric"
[1] "numeric"
typeof(numeros)    # Tipo: "double"
[1] "double"
import numpy as np

numeros = np.array([1, 3, 5, 7, 9])

len(numeros)       # Longitud: 5
5
type(numeros)      # Tipo: <class 'numpy.ndarray'>
<class 'numpy.ndarray'>
numeros.dtype      # Tipo de datos: dtype('int64')
dtype('int64')

5.3. Vectores nombrados

edades <- c(juan = 25, maria = 30, pedro = 28)
edades["juan"]     # 25
juan 
  25 
# Usando diccionario

edades = {"juan": 25, "maria": 30, "pedro": 28}
edades["juan"]     # 25
25
# Usando Series de pandas

import pandas as pd

edades_series = pd.Series([25, 30, 28], index=["juan", "maria", "pedro"])
edades_series["juan"] # 25
np.int64(25)

5.4. Indexación

En programación, y en particular en Python, indexación significa acceder a un elemento de una estructura de datos usando su posición (índice).

Un índice es el número que indica la posición de un elemento dentro de una secuencia (lista, tupla, cadena, array, etc.).

En Python, la indexación comienza en 0 (el primer elemento tiene índice 0, el segundo índice 1, y así sucesivamente).

letras <- c("a", "b", "c", "d", "e", "f")
letras[1]          # Primer elemento: "a" (base 1)
[1] "a"
letras[2:4]        # Rango: "b" "c" "d"
[1] "b" "c" "d"
letras[-1]         # Exclusión: todo excepto primero
[1] "b" "c" "d" "e" "f"
letras[c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE)] # Indexación lógica: "a" "c" "e"
[1] "a" "c" "e"
letras = ["a", "b", "c", "d", "e", "f"]
letras[0]          # Primer elemento: "a" (base 0)
'a'
letras[1:4]        # Rango: ["b", "c", "d"]
['b', 'c', 'd']
letras[1:]         # Todo desde índice 1: ["b", "c", "d", "e", "f"]
['b', 'c', 'd', 'e', 'f']
# Indexación booleana con numpy

import numpy as np
letras_arr = np.array(letras)
mask = [True, False, True, False, True, False]
letras_arr[mask]   # array(['a', 'c', 'e'], dtype='<U1')
array(['a', 'c', 'e'], dtype='<U1')

5.5. Modificación de vectores

(numeros <- c(10, 20, 30, 40, 50))
[1] 10 20 30 40 50
numeros[3] <- 35              # Cambiar elemento
numeros[numeros > 30] <- 0    # Modificación condicional

print(numeros)
[1] 10 20  0  0  0
import numpy as np

numeros = np.array([10, 20, 30, 40, 50])
print(numeros)
[10 20 30 40 50]
numeros[2] = 35               # Cambiar elemento
numeros[numeros > 30] = 0     # Modificación condicional
print(numeros)
[10 20  0  0  0]

6. Vectorización

6.1. Operaciones vectorizadas

x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6, 8, 10)
print(x)
[1] 1 2 3 4 5
print(y)
[1]  2  4  6  8 10
x + y        # Suma elemento a elemento: 3 6 9 12 15
[1]  3  6  9 12 15
x * 2        # Multiplicación por escalar: 2 4 6 8 10
[1]  2  4  6  8 10
x %*% y      # Producto punto: 110
     [,1]
[1,]  110
import numpy as np

x = np.array([1, 2, 3, 4, 5])
y = np.array([2, 4, 6, 8, 10])
print(x, y)
[1 2 3 4 5] [ 2  4  6  8 10]
x + y        # Suma elemento a elemento: array([3, 6, 9, 12, 15])
array([ 3,  6,  9, 12, 15])
x * 2        # Multiplicación por escalar: array([2, 4, 6, 8, 10])
array([ 2,  4,  6,  8, 10])
np.dot(x, y) # Producto punto: 110
np.int64(110)

6.2. Funciones vectorizadas

sqrt(c(1, 4, 9, 16, 25))      # Raíces: 1 2 3 4 5
[1] 1 2 3 4 5
log(c(1, 10, 100))            # Log natural: 0.000000 2.302585 4.605170
[1] 0.000000 2.302585 4.605170
import numpy as np

np.sqrt([1, 4, 9, 16, 25])   # Raíces: array([1., 2., 3., 4., 5.])
array([1., 2., 3., 4., 5.])
np.log([1, 10, 100])         # Log natural: array([0., 2.30258509, 4.60517019])
array([0.        , 2.30258509, 4.60517019])

6.3. Reciclado de vectores

c(1, 2, 3, 4, 5, 6) + c(10, 100) # Reciclado: 11 102 13 104 15 106
[1]  11 102  13 104  15 106
import numpy as np

# No hay reciclado automático, se debe usar broadcasting
# np.array([1, 2, 3, 4, 5, 6]) + np.array([10, 100]) # Error

# Solución con tile o resize
a = np.array([1, 2, 3, 4, 5, 6])
b = np.tile([10, 100], 3)  # array([10, 100, 10, 100, 10, 100])
a + b  # array([11, 102, 13, 104, 15, 106])
array([ 11, 102,  13, 104,  15, 106])

7. Funciones Estadísticas

7.1. Estadísticas descriptivas

datos <- c(12, 15, 18, 22, 25, 28, 30, 35, 38, 42)
mean(datos)     # Media: 26.5
[1] 26.5
median(datos)   # Mediana: 26.5
[1] 26.5
sd(datos)       # Desviación estándar: 10.24695
[1] 9.980537
var(datos)      # Varianza: 105
[1] 99.61111
sum(datos)      # Suma: 265
[1] 265
import numpy as np

datos = np.array([12, 15, 18, 22, 25, 28, 30, 35, 38, 42])
np.mean(datos)  # Media: 26.5
np.float64(26.5)
np.median(datos) # Mediana: 26.5
np.float64(26.5)
np.std(datos)   # Desviación estándar: 10.246950765959598
np.float64(9.468368391650168)
np.var(datos)   # Varianza: 105.0
np.float64(89.65)
np.sum(datos)   # Suma: 265
np.int64(265)

7.2. Funciones acumulativas

cumsum(datos)   # Suma acumulativa: 12 27 45 67 92 120 150 185 223 265
 [1]  12  27  45  67  92 120 150 185 223 265
cumprod(datos)  # Producto acumulativo
 [1] 1.200000e+01 1.800000e+02 3.240000e+03 7.128000e+04 1.782000e+06
 [6] 4.989600e+07 1.496880e+09 5.239080e+10 1.990850e+12 8.361572e+13
import numpy as np

np.cumsum(datos) # Suma acumulativa: [12 27 45 67 92 120 150 185 223 265]
array([ 12,  27,  45,  67,  92, 120, 150, 185, 223, 265])
np.cumprod(datos) # Producto acumulativo
array([            12,            180,           3240,          71280,
              1782000,       49896000,     1496880000,    52390800000,
        1990850400000, 83615716800000])

8. Matrices y Arrays

8.1. Creación de matrices

Una matriz es un caso particular de array bidimensional (filas y columnas) especializado en operaciones de álgebra lineal como multiplicación matricial, cálculo de determinantes, inversas y resolución de sistemas de ecuaciones, siendo fundamental en aplicaciones como gráficos por computadora, procesamiento de imágenes y machine learning.

mat <- matrix(1:12, nrow = 3, ncol = 4)
#      [,1] [,2] [,3] [,4]
# [1,]    1    4    7   10
# [2,]    2    5    8   11
# [3,]    3    6    9   12

print(mat)
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
import numpy as np
mat = np.array(range(1, 13)).reshape(3, 4)
# array([[ 1,  2,  3,  4],
#        [ 5,  6,  7,  8],
#        [ 9, 10, 11, 12]])

print(mat)
[[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]]

8.2. Operaciones con matrices

mat <- matrix(1:12, nrow = 3, ncol = 4)

dim(mat)        # Dimensiones: 3 4
[1] 3 4
nrow(mat)       # Filas: 3
[1] 3
ncol(mat)       # Columnas: 4
[1] 4
mat[2, 3]       # Elemento: 8
[1] 8
mat[2, ]        # Fila 2: 2 5 8 11
[1]  2  5  8 11
t(mat)          # Transpuesta
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    4    5    6
[3,]    7    8    9
[4,]   10   11   12
mat %*% t(mat)  # Multiplicación matricial
     [,1] [,2] [,3]
[1,]  166  188  210
[2,]  188  214  240
[3,]  210  240  270
import numpy as np
mat = np.array(range(1, 13)).reshape(3, 4)

mat.shape       # Dimensiones: (3, 4)
(3, 4)
mat.shape[0]    # Filas: 3
3
mat.shape[1]    # Columnas: 4
4
mat[1, 2]       # Elemento: 8 (índices base 0)
np.int64(7)
mat[1, :]       # Fila 1: array([5, 6, 7, 8])
array([5, 6, 7, 8])
mat.T           # Transpuesta
array([[ 1,  5,  9],
       [ 2,  6, 10],
       [ 3,  7, 11],
       [ 4,  8, 12]])
np.dot(mat, mat.T) # Multiplicación matricial
array([[ 30,  70, 110],
       [ 70, 174, 278],
       [110, 278, 446]])

8.3. Arrays multidimensionales

Un array es una estructura de datos que almacena una colección de elementos del mismo tipo organizados en una o más dimensiones (vectores, matrices o tensores), permitiendo acceso eficiente mediante índices y operaciones numéricas rápidas, ideal para manejar datos científicos, señales, imágenes o cualquier conjunto homogéneo de valores en programación.

arr <- array(1:24, dim = c(2, 3, 4))
arr[1, 2, 3]    # Elemento: 15
[1] 15
import numpy as np

arr = np.arange(1, 25).reshape(2, 3, 4)
arr[0, 1, 2]    # Elemento: 15 (índices base 0)
np.int64(7)

9. Valores Especiales

NA      # Valor faltante
[1] NA
NaN     # No es un número
[1] NaN
Inf     # Infinito
[1] Inf
NULL    # Ausencia de valor
NULL
is.na(NA)   # TRUE
[1] TRUE
is.nan(0/0) # TRUE
[1] TRUE
is.finite(Inf) # FALSE
[1] FALSE
import numpy as np

np.nan      # No es un número
nan
np.inf      # Infinito
inf
None        # Ausencia de valor
np.isnan(np.nan)   # True
np.True_
np.isfinite(np.inf) # False
np.False_

10. Listas y Estructuras de Datos

10.1. Listas

Una lista es una estructura de datos ordenada y mutable que permite almacenar una colección de elementos de diferentes tipos (números, texto, otras listas, etc.) bajo un mismo nombre, accesibles mediante un índice numérico.

irve para agrupar, organizar y manipular múltiples elementos de manera flexible, permitiendo operaciones como agregar, eliminar, modificar y acceder a valores específicos, lo que la hace ideal para manejar conjuntos de datos variables, iterar sobre elementos con bucles y almacenar información heterogénea en programación.

lista <- list(a = 1, b = "texto", c = matrix(1:4, 2))

lista[[2]]      # Acceso por índice: "texto"
[1] "texto"
lista$b         # Acceso por nombre: "texto"
[1] "texto"
lista = {"a": 1, "b": "texto", "c": np.array([[1, 2], [3, 4]])}
lista["b"]      # Acceso por clave: "texto"
'texto'
# O usando clase personalizada o namedtuple

from collections import namedtuple

MiLista = namedtuple('MiLista', ['a', 'b', 'c'])
lista_obj = MiLista(1, "texto", np.array([[1, 2], [3, 4]]))
lista_obj.b     # "texto"
'texto'

10.2. Data Frames

Un DataFrame es una estructura de datos bidimensional (similar a una tabla de Excel o una tabla de base de datos) que organiza la información en filas (observaciones o registros) y columnas (variables o características), donde cada columna puede contener un tipo de dato diferente (números, texto, fechas, etc.).

Sirve para almacenar, manipular y analizar datos de manera eficiente, permitiendo operaciones como filtrado, ordenamiento, agrupación, limpieza de datos, cálculos estadísticos y visualización, siendo fundamental en el proceso de análisis y ciencia de datos en lenguajes como Python (con la librería Pandas) y R.

df <- data.frame(nombre = c("Juan", "Maria"), edad = c(25, 30))
df$edad         # Columna edad: 25 30
[1] 25 30
df[1, ]         # Primera fila
  nombre edad
1   Juan   25
print(df)
  nombre edad
1   Juan   25
2  Maria   30
import pandas as pd

df = pd.DataFrame({"nombre": ["Juan", "Maria"], "edad": [25, 30]})
df["edad"]      # Columna edad: 0:25, 1:30
0    25
1    30
Name: edad, dtype: int64
df.iloc[0]      # Primera fila
nombre    Juan
edad        25
Name: 0, dtype: object

11. Sistema de Ayuda

#Ejemplo de solicitud de ayuda del argumento 'mean'

?mean           # Ayuda de función
starting httpd help server ... done
help(mean)      # Ayuda de función
??mean          # Búsqueda amplia
example(mean)   # Ejemplos

mean> x <- c(0:10, 50)

mean> xm <- mean(x)

mean> c(xm, mean(x, trim = 0.10))
[1] 8.75 5.50
args(mean)      # Argumentos
function (x, ...) 
NULL
help(np.mean)   # Ayuda de función
Help on _ArrayFunctionDispatcher in module numpy:

mean(a, axis=None, dtype=None, out=None, keepdims=<no value>, *, where=<no value>)
    Compute the arithmetic mean along the specified axis.
    
    Returns the average of the array elements.  The average is taken over
    the flattened array by default, otherwise over the specified axis.
    `float64` intermediate and return values are used for integer inputs.
    
    Parameters
    ----------
    a : array_like
        Array containing numbers whose mean is desired. If `a` is not an
        array, a conversion is attempted.
    axis : None or int or tuple of ints, optional
        Axis or axes along which the means are computed. The default is to
        compute the mean of the flattened array.
    
        If this is a tuple of ints, a mean is performed over multiple axes,
        instead of a single axis or all the axes as before.
    dtype : data-type, optional
        Type to use in computing the mean.  For integer inputs, the default
        is `float64`; for floating point inputs, it is the same as the
        input dtype.
    out : ndarray, optional
        Alternate output array in which to place the result.  The default
        is ``None``; if provided, it must have the same shape as the
        expected output, but the type will be cast if necessary.
        See :ref:`ufuncs-output-type` for more details.
        See :ref:`ufuncs-output-type` for more details.
    
    keepdims : bool, optional
        If this is set to True, the axes which are reduced are left
        in the result as dimensions with size one. With this option,
        the result will broadcast correctly against the input array.
    
        If the default value is passed, then `keepdims` will not be
        passed through to the `mean` method of sub-classes of
        `ndarray`, however any non-default value will be.  If the
        sub-class' method does not implement `keepdims` any
        exceptions will be raised.
    
    where : array_like of bool, optional
        Elements to include in the mean. See `~numpy.ufunc.reduce` for details.
    
        .. versionadded:: 1.20.0
    
    Returns
    -------
    m : ndarray, see dtype parameter above
        If `out=None`, returns a new array containing the mean values,
        otherwise a reference to the output array is returned.
    
    See Also
    --------
    average : Weighted average
    std, var, nanmean, nanstd, nanvar
    
    Notes
    -----
    The arithmetic mean is the sum of the elements along the axis divided
    by the number of elements.
    
    Note that for floating-point input, the mean is computed using the
    same precision the input has.  Depending on the input data, this can
    cause the results to be inaccurate, especially for `float32` (see
    example below).  Specifying a higher-precision accumulator using the
    `dtype` keyword can alleviate this issue.
    
    By default, `float16` results are computed using `float32` intermediates
    for extra precision.
    
    Examples
    --------
    >>> import numpy as np
    >>> a = np.array([[1, 2], [3, 4]])
    >>> np.mean(a)
    2.5
    >>> np.mean(a, axis=0)
    array([2., 3.])
    >>> np.mean(a, axis=1)
    array([1.5, 3.5])
    
    In single precision, `mean` can be inaccurate:
    
    >>> a = np.zeros((2, 512*512), dtype=np.float32)
    >>> a[0, :] = 1.0
    >>> a[1, :] = 0.1
    >>> np.mean(a)
    np.float32(0.54999924)
    
    Computing the mean in float64 is more accurate:
    
    >>> np.mean(a, dtype=np.float64)
    0.55000000074505806 # may vary
    
    Computing the mean in timedelta64 is available:
    
    >>> b = np.array([1, 3], dtype="timedelta64[D]")
    >>> np.mean(b)
    np.timedelta64(2,'D')
    
    Specifying a where argument:
    
    >>> a = np.array([[5, 9, 13], [14, 10, 12], [11, 15, 19]])
    >>> np.mean(a)
    12.0
    >>> np.mean(a, where=[[True], [False], [False]])
    9.0
np.mean.__doc__ # Documentación
'\n    Compute the arithmetic mean along the specified axis.\n\n    Returns the average of the array elements.  The average is taken over\n    the flattened array by default, otherwise over the specified axis.\n    `float64` intermediate and return values are used for integer inputs.\n\n    Parameters\n    ----------\n    a : array_like\n        Array containing numbers whose mean is desired. If `a` is not an\n        array, a conversion is attempted.\n    axis : None or int or tuple of ints, optional\n        Axis or axes along which the means are computed. The default is to\n        compute the mean of the flattened array.\n\n        If this is a tuple of ints, a mean is performed over multiple axes,\n        instead of a single axis or all the axes as before.\n    dtype : data-type, optional\n        Type to use in computing the mean.  For integer inputs, the default\n        is `float64`; for floating point inputs, it is the same as the\n        input dtype.\n    out : ndarray, optional\n        Alternate output array in which to place the result.  The default\n        is ``None``; if provided, it must have the same shape as the\n        expected output, but the type will be cast if necessary.\n        See :ref:`ufuncs-output-type` for more details.\n        See :ref:`ufuncs-output-type` for more details.\n\n    keepdims : bool, optional\n        If this is set to True, the axes which are reduced are left\n        in the result as dimensions with size one. With this option,\n        the result will broadcast correctly against the input array.\n\n        If the default value is passed, then `keepdims` will not be\n        passed through to the `mean` method of sub-classes of\n        `ndarray`, however any non-default value will be.  If the\n        sub-class\' method does not implement `keepdims` any\n        exceptions will be raised.\n\n    where : array_like of bool, optional\n        Elements to include in the mean. See `~numpy.ufunc.reduce` for details.\n\n        .. versionadded:: 1.20.0\n\n    Returns\n    -------\n    m : ndarray, see dtype parameter above\n        If `out=None`, returns a new array containing the mean values,\n        otherwise a reference to the output array is returned.\n\n    See Also\n    --------\n    average : Weighted average\n    std, var, nanmean, nanstd, nanvar\n\n    Notes\n    -----\n    The arithmetic mean is the sum of the elements along the axis divided\n    by the number of elements.\n\n    Note that for floating-point input, the mean is computed using the\n    same precision the input has.  Depending on the input data, this can\n    cause the results to be inaccurate, especially for `float32` (see\n    example below).  Specifying a higher-precision accumulator using the\n    `dtype` keyword can alleviate this issue.\n\n    By default, `float16` results are computed using `float32` intermediates\n    for extra precision.\n\n    Examples\n    --------\n    >>> import numpy as np\n    >>> a = np.array([[1, 2], [3, 4]])\n    >>> np.mean(a)\n    2.5\n    >>> np.mean(a, axis=0)\n    array([2., 3.])\n    >>> np.mean(a, axis=1)\n    array([1.5, 3.5])\n\n    In single precision, `mean` can be inaccurate:\n\n    >>> a = np.zeros((2, 512*512), dtype=np.float32)\n    >>> a[0, :] = 1.0\n    >>> a[1, :] = 0.1\n    >>> np.mean(a)\n    np.float32(0.54999924)\n\n    Computing the mean in float64 is more accurate:\n\n    >>> np.mean(a, dtype=np.float64)\n    0.55000000074505806 # may vary\n\n    Computing the mean in timedelta64 is available:\n\n    >>> b = np.array([1, 3], dtype="timedelta64[D]")\n    >>> np.mean(b)\n    np.timedelta64(2,\'D\')\n\n    Specifying a where argument:\n\n    >>> a = np.array([[5, 9, 13], [14, 10, 12], [11, 15, 19]])\n    >>> np.mean(a)\n    12.0\n    >>> np.mean(a, where=[[True], [False], [False]])\n    9.0\n\n    '
# Ejemplos usualmente en documentación online

import inspect #Libreria para gestionar la ayuda de argumentos

inspect.signature(np.mean) # Argumentos
<Signature (a, axis=None, dtype=None, out=None, keepdims=<no value>, *, where=<no value>)>