Professional Documents
Culture Documents
Practice Sheet - 2 Introductions To Numpy
Practice Sheet - 2 Introductions To Numpy
1. Installation of NumPy
2. Import NumPy
Once NumPy is installed, import it in your applications by adding the import keyword:
import numpy
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.
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.