1.forma
# 1.forma # # Matriz unidimensional a = [1,2,3,4,5,6,7,8,9,10,11,12 ] b = matriz np. (a) print (b.shape [0 ]) # más externa elementos 12 # de impresión (b.shape [1]) veces el exterior #, # IndexError:. OUT índice tupla de Rango # ¿Por qué no a.shape [0], porque la 'lista' objeto tiene sin atributo 'forma' # Arreglo bidimensional a = [[1,2,3,4], [5,6,7,8], [ 9,10,11,12 ]] b = matriz np. (a) print (b) print (b.shape [0], b.shape [1]) # 3 capas más externas, 4 internas
# salida :
12 [[ 1 2 3 4 ] [ 5 6 7 8 ] [ 9 10 11 12 ]] 3 4
2.reforma
# 2.reformar a = [1,2,3,4,5,6,7,8,9,10,11,12 ] b = np.array (a) .reshape (2,6) # 2 líneas 6 Columna print (b) print (a) b = np.array (a) .reshape (2,3,2) # 2 filas y 3 columnas de dos matrices print (b) print (np.array (a)) # reshape La matriz recién generada y la matriz original comparten la misma memoria, sin importar qué cambios se afecten entre sí.
# Salida: [[1 2 3 4 5 6 ] [ 7 8 9 10 11 12 ]] [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] [[[ 1 2 ] [ 3 4 ] [ 5 6 ]] [[ 7 8 ] [ 9 10 ] [ 11 12 ]]] [ 1 2 3 4 5 6 7 8 9 10 11 12]
# 3.reforma (-1,1) se interpreta como: -1 fila == sin fila; 1 == 1 columna, entonces este es el vector de 1 columna a = [1,2,3,4,5,6,7 , 8,9,10,11,12 ] b = np.array (a) .reshape (-1,1 ) # 12 * 1 print (b) a = [1,2,3,4,5,6, 7,8,9,10,11,12 ] b = np.array (a) .reshape (-1,2 ) # 6 * 2 print (b) a = [1,2,3,4,5,6 , 7,8,9,10,11,12 ] b = np.array (a) .reshape (1, -1 ) # 1 * 12 print (b) a = [1,2,3,4,5, 6,7,8,9,10,11,12 ] b = np.array (a) .reshape (2, -1 ) # 2 * 6 print (b)
#Resultado : [[1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ]] [[ 1 2 ] [ 3 4 ] [ 5 6 ] [ 7 8 ] [ 9 10 ] [ 11 12 ]] [[1 2 3 4 5 6 7 8 9 10 11 12 ]] [[ 1 2 3 4 5 6 ] [ 7 8 9 10 11 12 ]] >>>
3. Cuando estaba estudiando esto, parecía referirme a ese sitio web, algunos de ellos no recordaban.