You are on page 1of 4

Name: ASWIN K

Roll number: AM.EN.U4CSE20114


Class: CSE B

PRACTICE SHEET – 2 INTRODUCTIONS TO NUMPY

1. Installation of NumPy

C:\Users\Your Name>pip install numpy

2. Import NumPy
Once NumPy is installed, import it in your applications by adding the import keyword:

import numpy

3. Create a NumPy ndarray Object


4. Create an array containing '1' as its items using the 'ones()' function from the 'numpy' module.

5. Using 'zeros()' function, create a NumPy array having 4 blocks, 2 rows and 3 columns. The items
should be int data-type.

6. Create a onedimensional array containing numbers between 5 and 20 using the 'arange()'
function in the NumPy module.

7. Create an array of numbers from 1 to 24 such that the difference between two consecutive
numbers is 4. Create an array of numbers from 1 to 24 such that the difference between two
consecutive numbers is 4 and each item is a float.

8. Create an array containing 4 numbers between 1 to 25.

9. Create an array containing 10 numbers between 1 and 25 such that the difference between two
consecutive numbers is constant.
10. Create a three-dimensional NumPy array containing 40 random integers between 50 and 100

11. Create a list of natural numbers from 1 to 15 using the list comprehension method. Then
convert the list into a NumPy array using the array() function.

12. Create a function to check whether the input lenghts represent the lengths of the side of a
triangle.

13. Create a function to calculate the area of a triangle using the Heron's formula.
14. Write a program to perform following two tasks:

Print the square root of numbers in the list. Compute the value of c in the equation c=(√a2+b2).

15. Write a program to change the dimension of an array (say my_arr =[1, 2, 3, 4, 5, 6, 7, 8, 9]) into a
3 X 3 (3 rows and 3 columns) array and convert this NumPy array into a list.

You might also like