Introduction to Packages Python Class 9 Notes

Teachers and Examiners (CBSESkillEduction) collaborated to create the Introduction to Packages Python Class 9 Notes. All the important Information are taken from the NCERT Textbook Artificial Intelligence (417).

Introduction to Packages Python Class 9 Notes

A package is simply a location where similar-type programmes, functions, or modules can be found. For diverse applications, there are a variety of free packages available (one of the benefits of Python being an open-source language).

The following are some of the readily available packages:

NumPy

A Python package for working with numerical arrays. It’s very useful for dealing with huge numerical databases and calculations.

Open CV

OpenCV is an image processing package that can deal explicitly with images and can be used for image manipulation and processing such as cropping, scaling, and editing, among other things.

Matplotlib

A software that aids in the visualisation of analytical data in graph form. It aids the user in better comprehending the data by allowing them to see it.

NLTK

Natural Language Tool Kit (NLTK) is a programme that aids in the processing of textual data. It is one of the most widely used Natural Lanague Processing packages.

Pandas

A Python library that aids in the processing of two-dimensional data tables. It comes in handy when working with data from Excel sheets or other databases.

Package Installation

Any package can be installed by directly writing the following command in the Anaconda

Step 1 : Open Anaconda Command Prompt

Step 2 : Type “conda install <package name>”

Step 3 : Press Enter

Step 4 : Proceed ([y]/n)?

Step 5 : Press “y”

Working with a package

To use a package, we must import it wherever it is needed in the script. In Python, there are several ways to import a differents version of package:

import numpy

Meaning: Import numpy into the file in order to use its features in the file where it was imported.

import numpy as np

Meaning: Import numpy and refer to it as np anywhere it’s used.

from numpy import array

Meaning: That is, only one functionality (array) from the entire numpy package is imported. While faster processing is achieved, the package’s usability is limited.

from numpy import array as arr

Meaning: Only one functionality (array) from the entire numpy package should be imported, and it should be referred to as arr whenever it is used.

What is NumPy?

NumPy, or Numerical Python, is the core Python library for performing mathematical and logical operations on arrays. When it comes to working with numbers, it is a widely utilised programme. NumPy provides a large range of arithmetic operations for working with numbers, making it easy to work with them. NumPy also works with arrays, which are just collections of data that are homogeneous.

An array is just a collection of many values of the same datatype. They can be numbers, characters, Booleans, and so on, but an array can only access one datatype at a time. The arrays used in NumPy are called ND-arrays (N-Dimensional Arrays) because NumPy has a function that allows you to create n-dimensional arrays in Python.

An array can easily be compared to a list. Let us take a look how different they are: 

NumPy ArraysList
Data collecting that is homogeneous.Data collecting that is heterogeneous.
Can only hold one sort of data, making datatypes inflexible.Datatypes are flexible because they can hold multiple types of data.
Cannot be initialised directly. It can only be used using the Numpy package.Because it is part of the Python grammar, it can be immediately initialised.
It is possible to perform direct numerical operations. For instance, dividing the entire array by three splits each element by three.It is not possible to perform direct numerical operations. For instance, dividing the entire list by three will not split each entry by three.
It is widely used in arithmetic.It’s often used to handle data.
Arrays consume less memory.Lists are given extra memory.
Illustration: To make a Numpy array named ‘A,’ follow these steps: A=numpy.array import numpy ([1,2,3,4,5,6,7,8,9,0]) Illustration: A = [1,2,3,4,5,6,7,8,9,0] to make a list
Introduction to Packages Python Class 9 Notes

Exploring NumPy!

The NumPy package has a number of features and functions that assist us with arithmetic and logical operations.

NumPy Arrays

Arrays are a collection of datatypes that are all the same name and same datatype.

We can use NumPy to generate n-dimensional arrays (where n can be any integer) and use other mathematical functions on them.

Here are various methods for creating arrays with the NumPy package, assuming the NumPy package has previously been loaded.

FunctionCode

Creating a Numpy Array 

numpy.array([1,2,3,4,5]) 

Creating a 2-Dimensional zero array (4X3 – 4 rows and 3 columns) 

numpy.zeros((4,3)) 

Creating an array with 5 random values

numpy.random.random(5) 

Creating a 2-Dimensional constant value array (3X4 – 3 rows and 4 columns) having all 6s

numpy.full((3,4),6) 

Creating a sequential array from 0 to 30 with gaps of 5

numpy.arrange(0,30,5) 

Introduction to Packages Python Class 9 Notes

Let’s have a look at some of the operations that could be performed on this array:

FunctionCode

Adding 5 to each element

ARR + 5

Divide each element by 5

ARR / 5

Squaring each element 

ARR ** 5

Accessing 2nd element of the array (element count starts from 0)

ARR[1]

Multiplying 2 arrays {consider BRR = numpy.array([6,7,8,9,0]) }

ARR * BRR

Introduction to Packages Python Class 9 Notes

As you can see, you can perform direct arithmetic operations on individual array members by manipulating the entire array variable.

Let us look at the functions which talk about the properties of an array: 

FunctionCode

Type of an array 

type(ARR)

Check the dimensions of an array

ARR.ndim 

Shape of an array 

ARR.shape 

Size of an array

ARR.size 

Datatype of elements stored in the array 

ARR.dtype

Introduction to Packages Python Class 9 Notes

Some other mathematical functions available with NumPy are: 

FunctionCode

Finding out maximum element of an array

ARR.max() 

Finding out row-wise maximum elements

ARR.max(axis = 1) 

Finding out column-wise minimum elements 

ARR.min(axis = 0)

Sum of all array elements 

ARR.sum() 

Introduction to Packages Python Class 9 Notes

Employability skills Class 9 Notes

Employability skills Class 9 MCQ

Employability skills Class 9 Questions and Answers

Aritificial Intelligence Class 9 Notes

Aritificial Intelligence Class 9 MCQ

Artificial Intelligence Class 9 Questions and Answers

Reference Textbook

The above Introduction to Packages Python Class 9 Notes was created using the NCERT Book and Study Material accessible on the CBSE ACADEMIC as a reference.

Disclaimer – 100% of the questions are taken from the CBSE textbook Introduction to Packages Python Class 9 Notes, our team has tried to collect all the correct Information from the textbook . If you found any suggestion or any error please contact us anuraganand2017@gmail.com.

error: Content is protected !!