Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python NumPy insert Function Syntax

numpy.insert(array, object, values, axis = None)
Comment

Python NumPy insert Function Example Working with arrays

# welcome to softhunt.net
# Python Program illustrating
# numpy.insert()

import numpy as np

#Working on 1D
arr = np.arange(5)
print("1D arr : 
", arr)
print("Shape : ", arr.shape)

# value = 9
# index = 1
# Insertion before first index
a = np.insert(arr, 1, 9)
print("
Array after insertion : ", a)
print("Shape : ", a.shape)


# Working on 2D array
arr = np.arange(12).reshape(3, 4)
print("

2D arr : 
", arr)
print("Shape : ", arr.shape)

a = np.insert(arr, 1, 9, axis = 1)
print("
Array after insertion : 
", a)
print("Shape : ", a.shape)
Comment

numpy insert

b = a.flatten()
>>> b
array([1, 1, 2, 2, 3, 3])
>>> np.insert(b, [2, 2], [5, 6])
array([1, 1, 5, ..., 2, 3, 3])
Comment

PREVIOUS NEXT
Code Example
Python :: encode url 
Python :: explode function in python 
Python :: remove a part of a string python 
Python :: python web scraping 
Python :: start index from 1 in python 
Python :: Replace an item in a python list 
Python :: python sandbox 
Python :: space complexity python 
Python :: python code to convert csv to xml 
Python :: how to find the last occurrence of a character in a string in python 
Python :: python print in the same line 
Python :: how to append data in django queryset 
Python :: python list operation 
Python :: longest palindromic substring using dp 
Python :: any all in python 
Python :: how to index lists in python 
Python :: Python list loop tutorial 
Python :: set intersection 
Python :: convert mixed number string to float 
Python :: plotly change legend name 
Python :: cast as float python 
Python :: Yield Expressions in python 
Python :: function composition python 
Python :: how to run other python files in python 
Python :: dfs algorithm 
Python :: python pandas sum of series 
Python :: csv to excel python 
Python :: add column to dataframe pandas 
Python :: Python NumPy Reshape function example 
Python :: python dict 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =