🔵 Data Science  ·  Lesson 35

NumPy Arrays

NumPy Arrays

What are NumPy Arrays?

NumPy Arrays means numPy arrays store numerical data efficiently and support fast mathematical operations.

In real programs, this topic helps in fast numeric calculation. Learn the idea first, then type the program yourself and compare the output.

💡 At a Glance
PointDetails
Course AreaData Science
Tools and concepts used to analyse, clean and present data.
Main Usefast numeric calculation
Example Filenumpy-arrays.py
Practice FocusRun, change values, and explain the output line by line.

Why should you learn this?

  • It is useful for fast numeric calculation.
  • It connects with matrix/vector operations.
  • It improves your ability to read, write and debug Python programs.

Important Terms

These terms are used directly in this lesson. Understand them before memorising the code.

TermMeaning
ndarrayMain NumPy array object.
arrayEfficient collection of same-type numerical values.
shapeDimensions of an array.
dtypedtype is an important term in this topic.
vectorizationPerforming operations on whole arrays without Python loops.

Syntax / Basic Pattern

The simple pattern is: prepare data, apply the concept, then show the result.

Basic Pattern
import numpy as np
marks = np.array([78, 85, 91, 66])
print(marks)
print("Mean:", marks.mean())
print("After bonus:", marks + 5)

Complete Example Program

Python – numpy-arrays.py
import numpy as np

marks = np.array([78, 85, 91, 66])
print(marks)
print("Mean:", marks.mean())
print("After bonus:", marks + 5)

Expected Output

[78 85 91 66] Mean: 80.0 After bonus: [83 90 96 71]

Program Explanation

  • import numpy as np imports ready-made features from a module/library.
  • marks = np.array([78, 85, 91, 66]) stores a value in marks.
  • print(marks) displays information or calculated result on the screen.
  • print("Mean:", marks.mean()) displays information or calculated result on the screen.
  • print("After bonus:", marks + 5) displays information or calculated result on the screen.

Where will you use it?

  • Fast numeric calculation.
  • Matrix/vector operations.
  • Preparing data for ml.

Common Mistakes

  • Analysing data before checking missing values, duplicates and data types.
  • Changing original data without keeping a clean copy.
  • Creating charts without title, labels or explanation.

Practice Tasks

  1. Type the program in numpy-arrays.py and run it.
  2. Change input values or sample data and observe the new output.
  3. Create one example related to fast numeric calculation.
  4. Write 5 lines explaining the logic in your own words.

Summary

NumPy Arrays is not a theory-only topic. You should be able to explain the meaning, write the example, run it successfully, and use it in a small practical program.

NumPy Arrays क्या है?

NumPy Arrays ka matlab hai: NumPy arrays store numerical data efficiently and support fast mathematical operations. Simple words me, ye topic practical Python programs likhne me direct use hota hai.

Is topic ko sirf definition ke liye nahi, balki fast numeric calculation jaise real examples ke liye practice karein.

यह क्यों सीखना जरूरी है?

  • Ye fast numeric calculation me kaam aata hai.
  • Ye matrix/vector operations se bhi connected hai.
  • Isse aap code ka output aur errors better samajh paate hain.

Important Terms

TermMeaning
ndarrayMain NumPy array object.
arrayEfficient collection of same-type numerical values.
shapeDimensions of an array.
dtypedtype is an important term in this topic.
vectorizationPerforming operations on whole arrays without Python loops.

Syntax / Basic Pattern

Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.

Basic Pattern
import numpy as np
marks = np.array([78, 85, 91, 66])
print(marks)
print("Mean:", marks.mean())
print("After bonus:", marks + 5)

Complete Example Program

Python – numpy-arrays.py
import numpy as np

marks = np.array([78, 85, 91, 66])
print(marks)
print("Mean:", marks.mean())
print("After bonus:", marks + 5)

Expected Output

[78 85 91 66] Mean: 80.0 After bonus: [83 90 96 71]

Program Explanation

  • import numpy as np imports ready-made features from a module/library.
  • marks = np.array([78, 85, 91, 66]) stores a value in marks.
  • print(marks) displays information or calculated result on the screen.
  • print("Mean:", marks.mean()) displays information or calculated result on the screen.
  • print("After bonus:", marks + 5) displays information or calculated result on the screen.

Practical Uses

  • Fast numeric calculation.
  • Matrix/vector operations.
  • Preparing data for ml.

Common Mistakes

  • Analysing data before checking missing values, duplicates and data types.
  • Changing original data without keeping a clean copy.
  • Creating charts without title, labels or explanation.

Practice Tasks

  1. Program ko numpy-arrays.py file me type karke run karein.
  2. Values change karke output compare karein.
  3. fast numeric calculation par ek छोटा example banayen.
  4. Logic ko apne words me 5 lines me likhein.

सारांश

NumPy Arrays ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.

← Back to Python Tutorial