Found 1204 Articles for Numpy

How to create a numpy array within a given range?

Prasad Naik
Updated on 16-Mar-2021 10:21:08

1K+ Views

We have to create a numpy array in the range provided by the user. We will use the arange() function in the numpy library to get our output.AlgorithmStep1: Import numpy. Step 2: Take start_value, end_value and Step from the user. Step 3: Print the array using arange() function in numpy.Example Codeimport numpy as np start_val = int(input("Enter starting value: ")) end_val = int(input("Enter ending value: ")) Step_val = int(input("Enter Step value: ")) print(np.arange(start_val, end_val, Step_val))OutputEnter starting value: 5 Enter ending value: 50 Enter Step value: 5 [ 5 10 15 20 25 30 35 40 45]

Print dates of today, yesterday and tomorrow using Numpy

Prasad Naik
Updated on 16-Mar-2021 10:10:45

291 Views

In this program, we will print today's, yesterday's and tomorrow's dates using the numpy library.AlgorithmStep 1: Import the numpy library. Step 2: find today's date using the datetime64() function. Step 3: find yesterday's date by subtracting the output of timedelta64() function from the output of datetime64() function. Step 4: Find yesterday's date by adding the output of timedelta64() function from the output of datetime64() function.Example Codeimport numpy as np todays_date = np.datetime64('today', 'D') print("Today's Date: ", todays_date) yesterdays_date = np.datetime64('today', 'D') - np.timedelta64(1, 'D') print("Yesterday's Date: ", yesterdays_date) tomorrows_date = np.datetime64('today', 'D') + np.timedelta64(1, 'D') print("Tomorrow's Date: ... Read More

How to draw different shapes using the Python Turtle library?

Prasad Naik
Updated on 16-Mar-2021 10:08:58

3K+ Views

In this program, we will draw different shapes using the Turtle library in Python. Turtle is a python feature like a drawing board, which lets you command a turtle to draw all over it. The different shapes that we are going to draw are square, rectangle, circle and a hexagon.AlgorithmStep 1: Take lengths of side for different shapes as input.Step 2: Use different turtle methods like forward() and left() for drawing different shapes.Example Codeimport turtle t = turtle.Turtle() #SQUARE side = int(input("Length of side: ")) for i in range(4):    t.forward(side)    t.left(90) #RECTANGLE side_a = int(input("Length of ... Read More

Linear Regression using PyTorch?

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

431 Views

About Linear RegressionSimple Linear Regression BasicsAllows us to understand relationship between two continuous variable.Example −x = independent variableweighty = dependent variableheighty = αx + βLet's understand simple linear regression through a program −#Simple linear regression import numpy as np import matplotlib.pyplot as plt np.random.seed(1) n = 70 x = np.random.randn(n) y = x * np.random.randn(n) colors = np.random.rand(n) plt.plot(np.unique(x), np.poly1d(np.polyfit(x, y, 1))(np.unique(x))) plt.scatter(x, y, c = colors, alpha = 0.5) plt.show()OutputPurpose of Linear Regression:to Minimize the distance between the points and the line (y = αx + β)AdjustingCoefficient: αIntercept/Bias: βBuilding a Linear Regression Model with PyTorchLet's ... Read More

Advertisements