This chapter introduces NumPy, a key library for numerical computing in Python, focusing on its array structure and operations.
Introduction to NumPy - Quick Look Revision Guide
Your 1-page summary of the most exam-relevant takeaways from Informatics Practices.
This compact guide covers 20 must-know concepts from Introduction to NumPy aligned with Class 11 preparation for Informatics Practices. Ideal for last-minute revision or daily review.
Complete study summary
Essential formulas, key terms, and important concepts for quick reference and revision.
Key Points
Define NumPy.
NumPy (Numerical Python) is a library for numerical computations, providing support for large multidimensional arrays and matrices.
How to install NumPy.
Install NumPy using the command: pip install numpy in the command prompt.
What is an Array?
An array is a data structure that holds items of the same type. It allows efficient data operation due to contiguous memory allocation.
Zero-based indexing.
Arrays use zero-based indexing, meaning the first element is accessed with index 0 and the last with index n-1.
NumPy array creation.
Use np.array() to create arrays. For example: array1 = np.array([1, 2, 3]) creates a 1-D array.
Creating 2-D arrays.
Pass nested lists to np.array(), e.g., np.array([[1, 2], [3, 4]]) creates a 2-D array.
Array attributes: ndim.
The attribute ndim returns the number of dimensions of the array. For example, a 2-D array returns 2.
Array attributes: shape.
The shape attribute returns the size of each dimension of the array as a tuple.
Array attributes: size.
The size attribute returns the total number of elements in the array, calculated as the product of elements in shape.
Element-wise operations.
Arrays support element-wise operations such as addition or multiplication. For example, A + B sums corresponding elements.
Reshape arrays.
Use the reshape() function to change the shape of an array without altering its data. Total elements remain the same.
Concatenate arrays.
NumPy's concatenate() function joins two or more arrays along a specified axis, ensuring aligned dimensions.
Split arrays.
Use numpy.split() to divide an array into multiple sub-arrays along an axis, specifying indices or number of splits.
Statistical operations.
Functions like max(), min(), mean(), and std() provide statistical analysis across array elements.
Loading arrays from text files.
Use np.loadtxt() and np.genfromtxt() to load data from text files into NumPy arrays.
Save arrays to disk.
The np.savetxt() function saves arrays to a text file, specifying delimiter and format using fmt parameter.
Type of ndarray.
NumPy arrays (ndarray) are flexible in shapes and types, enabling operations on large datasets efficiently.
Array types and memory.
Arrays must have elements of the same data type (e.g., int, float), optimizing memory and performance.
Array broadcasting.
Broadcasting allows operations on arrays of different shapes during arithmetic operations by 'stretching' smaller arrays.
Common mistakes.
Often students forget to use nested lists for 2-D arrays or mix element types, causing unexpected type promotions.
This chapter provides an insight into computer systems, including their components, importance, and evolution.
Start chapterThis chapter covers the emerging trends in technology, focusing on their significance and impact on society.
Start chapterThis chapter provides an overview of Python, a popular programming language, and its fundamental concepts necessary for building software.
Start chapterThis chapter explores lists and dictionaries, two essential data structures in programming, explaining their functions and importance for data manipulation.
Start chapterThis chapter introduces the concept of data, its collection, storage, processing, and statistical techniques used for analysis. Understanding data is critical in various fields for effective decision-making.
Start chapterThis chapter explores database concepts crucial for managing data electronically, particularly how databases can enhance data handling over manual methods.
Start chapterThis chapter introduces Structured Query Language (SQL) and its role in managing data within relational databases. It is essential for creating and manipulating databases effectively.
Start chapter