0% found this document useful (0 votes)
11 views3 pages

all python numpy program based on n

Uploaded by

kuldeepdamor56
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
11 views3 pages

all python numpy program based on n

Uploaded by

kuldeepdamor56
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

all python numpy program based on ncert

NumPy is a powerful library for numerical computing in Python. It provides


efficient operations on arrays and matrices, making it a valuable tool for tasks
like data analysis, scientific computing, and machine learning.

Here are some examples of NumPy programs based on NCERT (National Council of
Educational Research and Training) curriculum:

Creating Arrays

1D Array:
Python

import numpy as np

arr = np.array([1, 2, 3, 4, 5])


print(arr)
2D Array:
Python

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])


print(arr)
Array Operations

Addition:
Python

import numpy as np

arr1 = np.array([1, 2, 3])


arr2 = np.array([4, 5, 6])

sum_arr = arr1 + arr2


print(sum_arr)
Subtraction:
Python

import numpy as np

arr1 = np.array([1, 2, 3])


arr2 = np.array([4, 5, 6])

diff_arr = arr1 - arr2


print(diff_arr)
Multiplication:
Python

import numpy as np

arr1 = np.array([1, 2, 3])


arr2 = np.array([4, 5, 6])

product_arr = arr1 * arr2


print(product_arr)
Division:
Python

import numpy as np

arr1 = np.array([1, 2, 3])


arr2 = np.array([4, 5, 6])

quotient_arr = arr1 / arr2


print(quotient_arr)
Array Indexing and Slicing

Accessing elements:
Python

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr[0]) # Access the first element


print(arr[-1]) # Access the last element
Slicing:
Python

import numpy as np

arr = np.array([1, 2, 3, 4, 5])

print(arr[1:4]) # Access elements from index 1 to 3


print(arr[:3]) # Access elements from the beginning to index 2
print(arr[3:]) # Access elements from index 3 to the end
Array Shape Manipulation

Reshaping:
Python

import numpy as np

arr = np.array([1, 2, 3, 4, 5, 6])

new_arr = arr.reshape(2, 3)
print(new_arr)
Flattening:
Python

import numpy as np

arr = np.array([[1, 2, 3], [4, 5, 6]])

flat_arr = arr.flatten()
print(flat_arr)
These are just a few examples of NumPy programs based on the NCERT curriculum.
NumPy is a versatile library with many other features and functions that can be
explored further.
data

Gemini can make mistakes, so double-check it

You might also like