Sitemap
D Naresh

D Naresh

NumPy - Numerical Computing in Python

Python Made Easy - (Article 16) Telugu Explanation

4 min readNov 3, 2025

--

Press enter or click to view image in full size

1. What is NumPy?

NumPy ante “Numerical Python”.
Idi Python lo mathematical calculations fast ga cheyyadaniki use chestham.

Normally, lists tho calculations cheyyadam slow untundhi — because lists store mixed data (int, float, string etc.).
But NumPy lo, arrays use chestham → same data type, fast speed, less memory.

2. Why NumPy?

Normal ListNumPy ArrayStores mixed data typesOnly same type (ex: all int or all float)Slow calculationsVery fastNo advanced math functionsHas many built-in math functionsMemory usage moreMemory efficient

So, NumPy = Speed + Power + Simplicity

Press enter or click to view image in full size

3. Installing NumPy

Before using, install it (once only):

pip install numpy

Then import it in Python:

import numpy as np

np ane short name (alias) use chestham — easy typing kosam.

4. Creating NumPy Arrays

Press enter or click to view image in full size

(a) From a Python List:

import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)

Output:

[1 2 3 4 5]

Notice: NumPy arrays lo commas levu — that’s normal.

(b) 2D Array (Matrix like structure)

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

Output:

[[1 2 3]
[4 5 6]]

(c) Using Built-in Functions:

FunctionDescriptionnp.zeros(n)Create array with all zerosnp.ones(n)Create array with all onesnp.arange(start, stop, step)Like range() but gives NumPy arraynp.linspace(start, stop, num)Divides range into equal partsnp.eye(n)Creates identity matrix

Get D Naresh’s stories in your inbox

Join Medium for free to get updates from this writer.

Examples:

print(np.zeros(5))
print(np.ones(3))
print(np.arange(1, 10, 2))
print(np.linspace(0, 1, 5))
print(np.eye(3))

5. Array Properties

Press enter or click to view image in full size
a = np.array([[1,2,3],[4,5,6]])
print(a.ndim) # Dimension count (2D)
print(a.shape) # Rows, columns (2, 3)
print(a.size) # Total elements (6)
print(a.dtype) # Data type (int32 or float64)

6. Indexing & Slicing

Just like lists, but more powerful.

arr = np.array([10,20,30,40,50])
print(arr[0]) # First element
print(arr[-1]) # Last element
print(arr[1:4]) # Slice

2D Example:

arr2 = np.array([[10,20,30],
[40,50,60],
[70,80,90]])
print(arr2[0, 1])      # 20
print(arr2[:, 1]) # all rows, 2nd column
print(arr2[1:, :2]) # 2nd & 3rd row, first 2 columns

7. Mathematical Operations

NumPy arrays support element-wise operations (super fast).

a = np.array([1,2,3])
b = np.array([4,5,6])
print(a + b)     # [5 7 9]
print(a - b) # [-3 -3 -3]
print(a * b) # [ 4 10 18]
print(a / b) # [0.25 0.4 0.5]

8. Aggregate Functions

Press enter or click to view image in full size

Example:

arr = np.array([10,20,30,40,50])
print(np.sum(arr)) # 150
print(np.mean(arr)) # 30.0
print(np.std(arr)) # 14.142

9. Reshaping & Flattening

arr = np.arange(1, 10)
new_arr = arr.reshape(3, 3)
print(new_arr)
flat = new_arr.flatten()
print(flat)

10. Useful Functions

Press enter or click to view image in full size

Example:

a = np.array([1,2,3])
b = np.array([4,5,6])
print(np.concatenate((a,b)))

11. Random Numbers in NumPy

from numpy import random
print(random.randint(10))        # single random int
print(random.randint(1,100,5)) # array of 5 random ints
print(random.rand(3)) # 3 random floats between 0–1

12. Matrix Operations

a = np.array([[1,2],
[3,4]])
b = np.array([[5,6],
[7,8]])
print(np.dot(a,b))   # Matrix multiplication
print(a.T) # Transpose

13. Mini Example Program:

Calculate Average Marks using NumPy

import numpy as np
marks = np.array([78, 85, 69, 92, 88])
average = np.mean(marks)
highest = np.max(marks)
lowest = np.min(marks)
print("Average Marks:", average)
print("Highest Marks:", highest)
print("Lowest Marks:", lowest)

Key Takeaways:

  • NumPy = Fast, powerful numerical library
  • Arrays are homogeneous and fast
  • Easy slicing, reshaping, and mathematical operations
  • Perfect for Data Science, ML, and AI calculations

Practice Problems:

  1. Create a 3x3 matrix with numbers 1–9.
  2. Find the sum, mean, min, and max of that matrix.
  3. Generate 10 random integers and sort them.
  4. Combine two arrays horizontally and vertically.
  5. Create a 1D array → reshape it into 2x5 matrix.

Practice Problems:

Next Article: 17.Pandas: Data Analysis Library

Previous Article: 15.Writing Test Cases in Python (unittest Module)

--