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 :: remove last digit from number python 
Python :: maximum recursion depth exceeded while calling a Python object 
Python :: float python 
Python :: reshape IML matrix 
Python :: Split a list based on a condition 
Python :: identity matrix with numpy 
Python :: tkinter transparent background 
Python :: create QAction with icon in pyqt 
Python :: operators in python 
Python :: python how to make boxplots with swarmplot 
Python :: try and except in python 
Python :: pandas read parquet from s3 
Python :: for in print pyhton 
Python :: python remove second occurrence of character in string 
Python :: splitting strings in python 
Python :: copy array along axis numpy 
Python :: get maximum value index after groupby 
Python :: xlabel not showing matplotlib 
Python :: Python DateTime Date Class Example 
Python :: count occurrences of one variable grouped by another python 
Python :: Iterating With for Loops in Python 
Python :: channels_redis 
Python :: how to write user input to a file in python 
Python :: sample hierarchical clustering 
Python :: joining lists python 
Python :: parse email python 
Python :: Redirect the Python Script Output to File 
Python :: plot scattered dataframe 
Python :: add legend to colorbar 
Python :: num2words python 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =