KEMBAR78
Untitled2.ipynb - Colab | PDF | Computer Programming
0% found this document useful (0 votes)
38 views1 page

Untitled2.ipynb - Colab

Taller de programa no lineal

Uploaded by

Cristian Miranda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views1 page

Untitled2.ipynb - Colab

Taller de programa no lineal

Uploaded by

Cristian Miranda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Universidad de Córdoba

ING SISTEMAS

Curso: Diplomado Aprendizaje autónomo

Profesor: Cristian Revueltas

Alumno: Cristian David Miranda Garces y Juan Diego López

Fecha de Creación: 21/05/2024

Fecha Actualizada: 21/05/2024

import numpy as np

keyboard_arrow_down Punto #1
# Matriz unidimensional con números enteros usando NumPy
matriz_numpy = np.array([1, 2, 3, 4, 5,6,7,8,9,10])
print("")
print(matriz_numpy)

[ 1 2 3 4 5 6 7 8 9 10]

# Matriz bidimensional con números enteros usando NumPy


import numpy as np
matriz_2d_np = np.array([[1, 2, 3], [4, 5, 6]])
print("")
print(matriz_2d_np)

[[1 2 3]
[4 5 6]]

# Matriz tridimensional con números enteros usando NumPy


import numpy as np
matriz_3d_np = np.array([[[42, 22, 32], [43, 53, 63]], [[74, 84, 94], [100, 110, 120]]])
print("")
print(matriz_3d_np)

[[[ 42 22 32]
[ 43 53 63]]

[[ 74 84 94]
[100 110 120]]]

#Crear una matriz tipo zeros


matrizt_zeros= np.zeros((3,3,3))
print("")
print(matrizt_zeros)
print("")

[[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]

[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]

[[0. 0. 0.]
[0. 0. 0.]
[0. 0. 0.]]]

#Crear una matriz tridimensional (cubo) con forma (2, 3, 4), llena de ceros
import numpy as np
cubo = np.zeros((2, 3, 4), dtype=np.float32)
print(cubo)

[[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]

[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]]

#Crear una matriz tipo np.ones


import numpy as np
matrizt_one= np.ones((3,3,3))
print("")
print(matrizt_one)

[[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]

[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]

[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]]

#Creación de matrices con np.arange


import numpy as np
vector = np.arange(2,10,2)
print("")
print(vector)

[2 4 6 8]

#Creación de matrices con np.linspace


Array = np.linspace(0, 30, 10,endpoint=True)
print(Array)
print("")
Array = np.linspace(0, 30, 10,endpoint=True)
print(Array)

[ 0. 3.33333333 6.66666667 10. 13.33333333 16.66666667


20. 23.33333333 26.66666667 30. ]

[ 0. 3.33333333 6.66666667 10. 13.33333333 16.66666667


20. 23.33333333 26.66666667 30. ]

keyboard_arrow_down Punto #2
Indexación y segmentación

#Acceder al tercer elemento de un array unidimensional

Array_1d = np.array([14, 22, 33, 44, 55])


tercer_elemento = Array_1d[2]
print(Array_1d)
print("")
print(tercer_elemento)

[14 22 33 44 55]

33

#Extraer una subsecuencia del array


array = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
subsecuencia = array[2,2] # Extrae la fila 2 y columna 2
indexacion = array[1:3] # Extrae las filas 1 y 2
print(array)
print("")
print(subsecuencia)
print("")
print(indexacion)

[[1 2 3]
[4 5 6]
[7 8 9]]

[[4 5 6]
[7 8 9]]

#segmentacion de un array
temperaturas = np.array([[22, 25, 27, 23, 24, 26, 28],[20, 40, 50, 21, 26, 45, 42],[32, 36, 26, 31, 30, 12, 21]])
temperaturas_mayores_25 = temperaturas[temperaturas > 25]
print (temperaturas)
print("")
print("temperaturas por encima de 25 grados: ",temperaturas_mayores_25)

[[22 25 27 23 24 26 28]
[20 40 50 21 26 45 42]
[32 36 26 31 30 12 21]]

temperaturas por encima de 25 grados: [27 26 28 40 50 26 45 42 32 36 26 31 30]

Haz doble clic (o ingresa) para editar

keyboard_arrow_down Método "np.reshape"


#Cambiar la forma con np.reshape.
np.random.seed (10)
x = np.random.randint(1, 100, size=(4, 4))
y = np.random.randint(1, 100, size=(4, 4))
print("Matriz x:")
print(x)
print("\nMatriz y:")
print(y)
array_reshape_x = x.reshape(2, 8)
array_reshape_y = y.reshape(8, 2)
print("\narray que se redimensiono x:")
print(array_reshape_x)
print("\narray que se redimensiono y:")
print(array_reshape_y)

Matriz x:
[[10 16 65 29]
[90 94 30 9]
[74 1 41 37]
[17 12 55 89]]

Matriz y:
[[63 34 73 79]
[50 52 55 78]
[70 14 26 14]
[93 87 31 31]]

array que se redimensiono x:


[[10 16 65 29 90 94 30 9]
[74 1 41 37 17 12 55 89]]

array que se redimensiono y:


[[63 34]
[73 79]
[50 52]
[55 78]
[70 14]
[26 14]
[93 87]
[31 31]]

keyboard_arrow_down Operaciones básicas como Arrays


Suma
Resta
Multiplicación
División

# Crear dos arrays


array1 = np.array([1, 2, 3, 4])
array2 = np.array([5, 6, 7, 8])

# Suma de arrays
suma = np.add(array1, array2)
print("Suma:", suma)

# Resta de arrays
resta = np.subtract(array1, array2)
print("Resta:", resta)

# Multiplicación de arrays
multiplicacion = np.multiply(array1, array2)
print("Multiplicación:", multiplicacion)

# División de arrays
division = np.divide(array1, array2)
print("División:", division)

Suma: [ 6 8 10 12]
Resta: [-4 -4 -4 -4]
Multiplicación: [ 5 12 21 32]
División: [0.2 0.33333333 0.42857143 0.5 ]

You might also like