- NumPy Tutorial
- NumPy - Home
- NumPy - Introduction
- NumPy - Environment
- NumPy - Ndarray Object
- NumPy - Data Types
- NumPy - Array Attributes
- NumPy - Array Creation Routines
- NumPy - Array from Existing Data
- Array From Numerical Ranges
- NumPy - Indexing & Slicing
- NumPy - Advanced Indexing
- NumPy - Broadcasting
- NumPy - Iterating Over Array
- NumPy - Array Manipulation
- NumPy - Binary Operators
- NumPy - String Functions
- NumPy - Mathematical Functions
- NumPy - Arithmetic Operations
- NumPy - Statistical Functions
- Sort, Search & Counting Functions
- NumPy - Byte Swapping
- NumPy - Copies & Views
- NumPy - Matrix Library
- NumPy - Linear Algebra
- NumPy - Matplotlib
- NumPy - Histogram Using Matplotlib
- NumPy - I/O with NumPy
- NumPy Useful Resources
- NumPy Compiler
- NumPy - Quick Guide
- NumPy - Useful Resources
- NumPy - Discussion
numpy.resize
This function returns a new array with the specified size. If the new size is greater than the original, the repeated copies of entries in the original are contained. The function takes the following parameters.
numpy.resize(arr, shape)
Where,
Sr.No. | Parameter & Description |
---|---|
1 | arr Input array to be resized |
2 | shape New shape of the resulting array |
Example
import numpy as np a = np.array([[1,2,3],[4,5,6]]) print 'First array:' print a print '\n' print 'The shape of first array:' print a.shape print '\n' b = np.resize(a, (3,2)) print 'Second array:' print b print '\n' print 'The shape of second array:' print b.shape print '\n' # Observe that first row of a is repeated in b since size is bigger print 'Resize the second array:' b = np.resize(a,(3,3)) print b
The above program will produce the following output −
First array: [[1 2 3] [4 5 6]] The shape of first array: (2, 3) Second array: [[1 2] [3 4] [5 6]] The shape of second array: (3, 2) Resize the second array: [[1 2 3] [4 5 6] [1 2 3]]
numpy_array_manipulation.htm
Advertisements