L = list(range(10))
L
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
T = tuple(range(10))
T
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
import numpy as np
Npa = np.array(range(10))
Npa
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Np_cero = np.zeros(10)
Np_cero
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
Np_cero_int = np.zeros(10, dtype=int)
Np_cero_int
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
Np_uno = np.ones(10)
Np_uno
array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
Np_relleno = np.full(10,256)
Np_relleno
array([256, 256, 256, 256, 256, 256, 256, 256, 256, 256])
Np_rango = np.arange(10)
Np_rango
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
Np_random_dimensiones = np.random.randint(10, size=(3, 4))
Np_random_dimensiones
array([[3, 9, 2, 9], [6, 2, 3, 1], [1, 8, 8, 3]])
# Verificando el tipo de dato de array
arr = np.array([1, 2, 3, 4])
print(arr.dtype)
int64
arr = np.array(['apple', 'banana', 'cherry'])
print(arr.dtype)
<U6
arr = np.array([1, 2, 3, 4], dtype='S')
print(arr)
print(arr.dtype)
[b'1' b'2' b'3' b'4'] |S1
arr = np.array([1, 2, 3, 4], dtype='i4')
print(arr);print(arr.dtype)
[1 2 3 4] int32
arr = np.array([1.1, 2.1, 3.1])
newarr = arr.astype('i')
print(newarr)
print(newarr.dtype)
[1 2 3] int32
arr = np.array([1, 0, 3])
newarr = arr.astype(bool)
print(newarr)
print(newarr.dtype)
[ True False True] bool
Np_cero.ndim
1
Np_random_dimensiones.ndim
2
Np_random_dimensiones.shape
(3, 4)
Np_random_dimensiones.size
12
Np_cero.dtype
dtype('float64')
Np_cero_int.dtype
dtype('int64')
Np_random_dimensiones.itemsize
8
Np_cero.nbytes
80
Np_cero_int.nbytes
80
rango = range(1,11)
Np_diez_numeros = np.array(rango)
Np_diez_numeros
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Np_diez_numeros[0]
1
Np_diez_numeros[4]
5
Np_diez_numeros[-1]
10
Np_diez_numeros[-2]
9
Np_random_dimensiones
array([[3, 9, 2, 9], [6, 2, 3, 1], [1, 8, 8, 3]])
Np_random_dimensiones[2, 1]
8
Np_diez_numeros[:4]
array([1, 2, 3, 4])
Np_diez_numeros[3:]
array([ 4, 5, 6, 7, 8, 9, 10])
Np_diez_numeros[4:7]
array([5, 6, 7])
Np_diez_numeros[::2]
array([1, 3, 5, 7, 9])
Np_diez_numeros[::-2]
array([10, 8, 6, 4, 2])
Np_random_dimensiones[2,]
array([1, 8, 8, 3])
Np_random_dimensiones[:2, :2]
array([[3, 9], [6, 2]])
Np_random_dimensiones[2, 3]
3
np.arange(1,65)
Ajedrez_64 = np.arange(1,65).reshape(8,8)
Ajedrez_64
array([[ 1, 2, 3, 4, 5, 6, 7, 8], [ 9, 10, 11, 12, 13, 14, 15, 16], [17, 18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, 31, 32], [33, 34, 35, 36, 37, 38, 39, 40], [41, 42, 43, 44, 45, 46, 47, 48], [49, 50, 51, 52, 53, 54, 55, 56], [57, 58, 59, 60, 61, 62, 63, 64]])
Array_1 = np.random.randint(10, size=5)
Array_2 = np.random.randint(10, size=5)
Arrays_concatenados = np.concatenate([Array_1, Array_2])
Arrays_concatenados
array([1, 6, 7, 2, 0, 4, 4, 0, 7, 6])
Array_extra = np.array([[10],[20]])
Array_extra
array([[10], [20]])
Array_apilados_v = np.vstack([Array_extra, Array_extra])
Array_apilados_v
array([[10], [20], [10], [20]])
Array_apilados_h = np.hstack([Array_extra, Array_extra])
Array_apilados_h
array([[10, 10], [20, 20]])
Arrays_concatenados
array([1, 6, 7, 2, 0, 4, 4, 0, 7, 6])
Array_partido = np.split(Arrays_concatenados, [2])
Array_partido
[array([1, 6]), array([7, 2, 0, 4, 4, 0, 7, 6])]
Array_partido_2 = np.split(Arrays_concatenados, [2, 8])
Array_partido_2
[array([1, 6]), array([7, 2, 0, 4, 4, 0]), array([7, 6])]
Parte_1, Parte_2, Parte_3 = Array_partido_2
Parte_1
array([1, 6])
Parte_2
array([7, 2, 0, 4, 4, 0])
Parte_3
array([7, 6])
Ajedrez_partido_1 = np.hsplit(Ajedrez_64, [4])
Ajedrez_partido_1
[array([[ 1, 2, 3, 4], [ 9, 10, 11, 12], [17, 18, 19, 20], [25, 26, 27, 28], [33, 34, 35, 36], [41, 42, 43, 44], [49, 50, 51, 52], [57, 58, 59, 60]]), array([[ 5, 6, 7, 8], [13, 14, 15, 16], [21, 22, 23, 24], [29, 30, 31, 32], [37, 38, 39, 40], [45, 46, 47, 48], [53, 54, 55, 56], [61, 62, 63, 64]])]
Ajedrez_partido_2 = np.vsplit(Ajedrez_64, [4])
Ajedrez_partido_2
[array([[ 1, 2, 3, 4, 5, 6, 7, 8], [ 9, 10, 11, 12, 13, 14, 15, 16], [17, 18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 28, 29, 30, 31, 32]]), array([[33, 34, 35, 36, 37, 38, 39, 40], [41, 42, 43, 44, 45, 46, 47, 48], [49, 50, 51, 52, 53, 54, 55, 56], [57, 58, 59, 60, 61, 62, 63, 64]])]
Array_aleatorio = np.random.randint(10, size=10)
print(Array_aleatorio)
suma = 0
for i in Array_aleatorio:
suma += i
promedio = suma / np.size(Array_aleatorio)m
[6 3 4 1 2 2 0 3 1 5]
Array_aleatorio.sum()
27
Array_aleatorio.mean()
2.7
Array_aleatorio.max()
6
np.median(Array_aleatorio)
2.5
np.std(Array_aleatorio)
1.7916472867168918
np.var(Array_aleatorio)
3.21
Array_1
array([1, 6, 7, 2, 0])
Array_2
array([4, 4, 0, 7, 6])
Array_1+5
array([ 6, 11, 12, 7, 5])
Array_1 + Array_2
array([ 5, 10, 7, 9, 6])
np.add(Array_1, Array_2)
array([ 5, 10, 7, 9, 6])
np.matmul(Array_1, Array_2)
42