You are on page 1of 2

9/20/23, 8:34 PM 210090107120_Assignment5

Practical 5 : NumPy Library


Name : Priyansh Jain
Enrollment No : 210090107120
Class : III-A Batch - A3
Dataset Used : Online Retail 2
Dataset description : A real online retail transaction data set of two years.

Implement a program to create array with following data using NumPy module:

a. Array of numbers from 1 to 20 in reverse order


b. 2D array of size (3,4) with all elements filled with 8.
c. Array of 10 values which is evenly spaced in the range of 1 to 5
d. Array of 10 values which is evenly spaced in the range of 1 to 5 but on log scale
e. Array of 10 random numbers in the range of 1 to 100

In [ ]: import numpy as np

# a. Array of numbers from 1 to 20 in reverse order


array_a = np.arange(20, 0, -1)

# b. 2D array of size (3,4) with all elements filled with 8


array_b = np.full((3, 4), 8)

# c. Array of 10 values which is evenly spaced in the range of 1 to 5


array_c = np.linspace(1, 5, 10)

# d. Array of 10 values which is evenly spaced in the range of 1 to 5 but on a l


array_d = np.logspace(0, 1, 10)

# e. Array of 10 random numbers in the range of 1 to 100


array_e = np.random.randint(1, 101, 10)

# Display the arrays


print("a. Array from 1 to 20 in reverse order:\n", array_a)
print("\nb. 2D array (3x4) with all elements as 8:\n", array_b)
print("\nc. Array of 10 evenly spaced values between 1 and 5:\n", array_c)
print("\nd. Array of 10 evenly spaced values between 1 and 10 on a log scale:\n"
print("\ne. Array of 10 random numbers between 1 and 100:\n", array_e)

file:///C:/Users/Priyansh/Desktop/python assignments/Priyansh/210090107120_Assignment5.html 1/2


9/20/23, 8:34 PM 210090107120_Assignment5

a. Array from 1 to 20 in reverse order:


[20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1]

b. 2D array (3x4) with all elements as 8:


[[8 8 8 8]
[8 8 8 8]
[8 8 8 8]]

c. Array of 10 evenly spaced values between 1 and 5:


[1. 1.44444444 1.88888889 2.33333333 2.77777778 3.22222222
3.66666667 4.11111111 4.55555556 5. ]

d. Array of 10 evenly spaced values between 1 and 10 on a log scale:


[ 1. 1.29154967 1.66810054 2.15443469 2.7825594 3.59381366
4.64158883 5.9948425 7.74263683 10. ]

e. Array of 10 random numbers between 1 and 100:


[22 77 28 15 41 44 37 46 49 23]

file:///C:/Users/Priyansh/Desktop/python assignments/Priyansh/210090107120_Assignment5.html 2/2

You might also like