Python NumPy | GeeksforGeeks
Python NumPy | GeeksforGeeks
Python NumPy
Last Updated : 26 Mar, 2025
Besides its obvious scientific uses, Numpy can also be used as an efficient
multi-dimensional container of generic data.
Arrays in Numpy
Array in Numpy is a table of elements (usually numbers), all of the same
type, indexed by a tuple of positive integers. In Numpy, number of
dimensions of the array is called rank of the array. A tuple of integers giving
the size of the array along each dimension is known as shape of the array.
An array class in Numpy is called as ndarray. Elements in Numpy arrays
are accessed by using square brackets and can be initialized by using
nested Python Lists.
Output
Output
Elements at indices (1, 3), (1, 2), (0, 1), (3, 0):
[0. 6. 2. 3.]
1 import numpy as np
2
3 # Defining Array 1
4 a = np.array([[1, 2],
5 [3, 4]])
6
7 # Defining Array 2
8 b = np.array([[4, 3],
9 [2, 1]])
10
11 # Adding 1 to every element
12 print ("Adding 1 to every element:", a + 1)
13
14 # Subtracting 2 from each element
15 print ("\nSubtracting 2 from each element:", b - 2)
16
17 # sum of array elements
18 # Performing Unary operations
19 print ("\nSum of all array elements: ", a.sum())
20
21 # Adding two arrays
22 # Performing Binary operations
23 print ("\nArray sum:\n", a + b)
Output
Array sum:
[[5 5]
[5 5]]
Output
int64
float64
int64
Output
Transpose of Array:
[[4. 2.]
...
Methods in Numpy:
Programs on Numpy
ku… Follow
numpy.loadtxt() in Python
numpy.loadtxt() function is used to load data from a text file and return
it as a NumPy array. It is ideal for reading large data sets that are…
stored in simple text forma...
15+ min read
numpy.multiply() in Python
The numpy.multiply() is a numpy function in Python which is used to
find element-wise multiplication of two arrays or scalar (single value)…
It returns the product of two...
15+ min read
Python 101
Welcome to "Python 101," your comprehensive guide to
understanding and mastering the fundamentals of Python…
programming. Python is a versatile and powerful high-level prog...
15+ min read
Python for AI
:
Python for AI
Python has become the go-to programming language for artificial
intelligence (AI) development due to its simplicity and the powerful…
suite of libraries it offers. Its synt...
15+ min read
Registered Address:
K 061, Tower K, Gulshan Vivante
Apartment, Sector 137, Noida, Gautam
Buddh Nagar, Uttar Pradesh, 201305
Advertise with us
Company
About Us
Legal
Privacy Policy
Careers
In Media
Contact Us
GfG Corporate Solution
Placement Training Program
Explore
Job-A-Thon Hiring Challenge
GfG Weekly Contest
Offline Classroom Program
DSA in JAVA/C++
Master System Design
Master CP
GeeksforGeeks Videos
Languages
Python
Java
C++
PHP
GoLang
SQL
:
R Language
Android Tutorial
DSA
Data Structures
Algorithms
DSA for Beginners
Basic DSA Problems
DSA Roadmap
DSA Interview Questions
Competitive Programming
Web Technologies
HTML
CSS
JavaScript
TypeScript
ReactJS
NextJS
NodeJs
Bootstrap
Tailwind CSS
Python Tutorial
Python Programming Examples
Django Tutorial
Python Projects
Python Tkinter
Web Scraping
OpenCV Tutorial
Python Interview Question
Computer Science
:
Computer Science
GATE CS Notes
Operating Systems
Computer Network
Database Management System
Software Engineering
Digital Logic Design
Engineering Maths
DevOps
Git
AWS
Docker
Kubernetes
Azure
GCP
DevOps Roadmap
System Design
High Level Design
Low Level Design
UML Diagrams
Interview Guide
Design Patterns
OOAD
System Design Bootcamp
Interview Questions
School Subjects
Mathematics
Physics
Chemistry
Biology
Social Science
English Grammar
Databases
SQL
MYSQL
PostgreSQL
PL/SQL
MongoDB
:
Preparation Corner
Company-Wise Recruitment Process
Aptitude Preparation
Puzzles
Company-Wise Preparation
More Tutorials
Software Development
Software Testing
Product Management
Project Management
Linux
Excel
All Cheat Sheets
Programming Languages
C Programming with Data Structures
C++ Programming Course
Java Programming Course
Python Full Course
Clouds/Devops
DevOps Engineering
AWS Solutions Architect Certification
Salesforce Certified Administrator Course
GATE 2026
GATE CS Rank Booster
GATE DA Rank Booster
GATE CS & IT Course - 2026
GATE DA Course 2026
GATE Rank Predictor