#!/usr/bin/env python3 # Cargar librería import numpy as np # Crear un vector como fila vector = np.array([1, 2, 3, 4, 5, 6]) # Crear una matriz matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) # Seleccionar todos los elementos del vector print(vector[:]) # array([1, 2, 3, 4, 5, 6]) # Seleccionar hasta el 3º elemento incluido print(vector[:3]) # array([1, 2, 3]) # Todo despues del 3º elemento print(vector[3:]) # array([4, 5, 6]) # Último elemento print(vector[-1]) # 6 # Primeras dos filas y todas las columnas print(matrix[:2,:]) #array([[1, 2, 3], [4, 5, 6]]) # Initial Array arr = np.array([[-1, 2, 0, 4], [4, -0.5, 6, 0], [2.6, 0, 7, 8], [3, -7, 4, 2.0]]) print("Initial Array: ") print(arr) # Printing a range of Array # with the use of slicing method sliced_arr = arr[:2, ::2] print ("Array with first 2 rows and" " alternate columns(0 and 2):\n", sliced_arr) # Printing elements at # specific Indices Index_arr = arr[[1, 1, 0, 3], [3, 2, 1, 0]] print ("\nElements at indices (1, 3), " "(1, 2), (0, 1), (3, 0):\n", Index_arr)