Coding in week 2

Why do we need to import copy and math libraries separately when we are importing numpy wouldnt numpy include math functions.
import numpy as np
import matplotlib.pyplot as plt
from utils import *
import copy
import math

Hello @Jasmine7

Hope your enjoying your new learning journey.

The reason for importing copy and math including numpy is basically for the reason in this particular pretest
for math calculation of scalar data(or to say do simple mathematical computation) where as
in numpy math, uses for more of scientific computation with matrices, or array or any large dataset

When you go down in the assignment, the parameter of the model is a scalar data that is w which while computing cost uses the import math computation.

And import copy was again imported for the scalar data, if you see in the section gradient descent as the shape should be maintained and using numpy could cause this problem of converting it into an array.


1 Like

‘numpy’ has many mathematical functions, but they are different than the ones in the ‘math’ package.