<jupyter_start><jupyter_text>Introduction to Python 5 Modules and Numpy Herramientas Computacionales UniandesBased on [SoloLearn Python](https://www.sololearn.com/Play/Python)  Pip Install Modules<jupyter_code># To install a library we use a Linux command
!pip install colorama
import colorama
from colorama import Fore, Style
Fore??
print(Fore.BLUE + "Hello World")
import tensorflow as tf
from tensorflow.keras.layers import Dense
Dense??<jupyter_output><empty_output><jupyter_text>Numpy Arrays<jupyter_code>import numpy as np
# Creating a numpy array
a = np.array([[1,2,3,4],[5,6,7,8]])

a
# Selecting an element in two diferent ways
print(a[0][1])
print(a[0, 1])
# Attributes of a numpy array
print(a.ndim)
print(a.shape)
print(a.size)
print(type(a))<jupyter_output>2
(2, 4)
8
<class 'numpy.ndarray'><jupyter_text>Initializing a numpy array<jupyter_code># Array of ones
b = np.ones((2,3))

b
# Array of zeros
c = np.zeros((2,4))

c
h = np.full((2,4), 3)
h
# Array of random numbers
d = np.random.random((2,4))

d
# Identity matrix
#g = np.eye(4)
g = np.identity(4)
g<jupyter_output><empty_output><jupyter_text>Creating ranges in numpy arrays<jupyter_code>l = range(10)
print([i for i in range(10)])
# numpy range
j = np.arange(10)
print(j)
# numpy range
i = np.arange(0,10,2)
print(i)
# Creating a list with numbers in between
k= np.linspace(0,10,36)
print(k)<jupyter_output>[ 0.          0.28571429  0.57142857  0.85714286  1.14285714  1.42857143
  1.71428571  2.          2.28571429  2.57142857  2.85714286  3.14285714
  3.42857143  3.71428571  4.          4.28571429  4.57142857  4.85714286
  5.14285714  5.42857143  5.71428571  6.          6.28571429  6.57142857
  6.85714286  7.14285714  7.42857143  7.71428571  8.          8.28571429
  8.57142857  8.85714286  9.14285714  9.42857143  9.71428571 10.        ]<jupyter_text>Utils Functions<jupyter_code># Reshaping a matrix
l = np.array([[1,2,3],[4,5,6]])
print(l)
#print(l.shape)
print(l.reshape(3,2))<jupyter_output>[[1 2 3]
 [4 5 6]]
[[1 2]
 [3 4]
 [5 6]]<jupyter_text>Slicing numpy arrays<jupyter_code># Create an array
m = np.arange(8)
print(m)
# Slicing
n = m[::-1]
print(n)
o = m[:5]
print(o)
p = m[6:]
print(p)
# Changing a value of the array
m[4] = 100
print(m)
# Multidimensional slicing
q = np.array([[10,11,12,13],[20,22,23,25]])
print(q)
# # Select some elements
#print(q[0:1,1])
# Select a column
# print(q[:,0])
# # Select a row
print(q[1,:])<jupyter_output>[[10 11 12 13]
 [20 22 23 25]]
[20 22 23 25]<jupyter_text>Arithmetic Operations<jupyter_code>x = np.array([[1,2,3,4],[5,6,7,8]])
y = np.array([[9,10,11,12],[13,14,15,16]])
# Add two matrices
z = x + y
print(z)
# Numpy functions
a = np.exp(x)
print(a)
b = np.sqrt(x)
print(b)
# Matrix multiplication, the shapes do not align for matrix multiplication
c = np.dot(x, y)
print(c)
# Matrix multiplication
c = np.dot(x, y.T)
print(c)
# Matrix multiplication
print(x @ y.T)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15276828434723172, 'fraction_numerical': 0.1421736158578264, 'mean_word_length': 4.628846153846154, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '394899', 'license': 'MIT', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1273, 'n_words': 301, 'path': 'Notebooks/python 5 - modules and numpy.ipynb', 'repo_name': 'diegour1/HerramientasComputacionales', 'size': '2926'}