## Numpy exercise

Anything related to deep learning, machine learning, data science, and artificial intelligence. Course topic requests can go here.
Rodri
Posts: 4
Joined: Mon Jun 15, 2020 8:33 am

### Numpy exercise

Hi to all! I would like to share my results of Numpy exercise.
I have used a similar method used in numpy lecture, but using "time.perf_counter()" instead of "datetime.now()", why? because I did not find any difference and I usually use that.
The code is shown as follows:

Code: Select all

``````import numpy as np
import time

A = np.array([[1,2,3], [4,5,6], [7,8,9]])
#A = np.ones((3,3)) * 3
B = np.ones((3,3)) * 2
X = np.zeros((3,3))     #Matrix dot solution

sum1 = 0
sum2 = 0
med1 = 0
med2 = 0

#Manual method
for loop in range(0,500):

t1 = time.perf_counter()
for k in range(0,2+1):
for i in range(0,2+1):
e = 0
for j in range(0,2+1):
e = e + (A[k,j] * B[j,i])
X[k,i] = e
t2 = time.perf_counter()

sum1 = sum1 + (t2 - t1)
med1 = sum1/50

for loop2 in range(0,500):

t1 = time.perf_counter()
A.dot(B)
t2 = time.perf_counter()``````