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
|
import numpy
numeros_primos = [2,3,5,7,11,13,17,19,23,29]
array_primos = numpy.array(numeros_primos)
array_primos
# Output -> array([ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29])
array_zeros = numpy.zeros(10)
array_zeros
# Output -> array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
array_numeros = numpy.arange(10)
array_numeros
# Output -> array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
array_pares = numpy.arange(0,20,2)
array_pares
# Output -> array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])
array_pares.reshape(2,5)
# Output -> array([[ 0, 2, 4, 6, 8],
# [10, 12, 14, 16, 18]])
array_impares = array_pares + 1
array_impares
# Output -> array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19])
array_impares - array_pares # permite suma, resta, multiplicación...
# Output -> array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
array_primos.sum() # suma todos las posiciones 129
array_primos.mean() # media de todas las posiciones 12.9
array_primos.var() # varianza del array 73.28999999999999
array_fibonacci = numpy.array([55,0,144,1,21,89,5,8,13,1,34,3,2])
numpy.sort(array_fibonacci)
# Output -> array([ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]
numpy.sort(-array_fibonacci)
# Output -> array([-144, -89, -55, -34, -21, -13, -8, -5, -3, -2, -1, -1, 0])
A = numpy.arange(0,20,2).reshape(2,5)
A
# Output -> array([[ 0, 2, 4, 6, 8],
# [10, 12, 14, 16, 18]])
A[1,1] # 12
A[1,:] # array([10, 12, 14, 16, 18]) -> Selecciona solo una fila
A[:,1] # array([ 2, 12]) -> Selecciona solo una columna
array_fibonacci<20 # array([False, True, False, True, False, False, True, True, True, True, False, True, True])
array_fibonacci[array_fibonacci<20] # array([ 0, 1, 5, 8, 13, 1, 3, 2])
|