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 :: if statement python explained 
Python :: Print statement with multiple variables 
Python :: check if text is python 
Python :: df loc 
Python :: run python module from command line 
Python :: check if boolean is true python 
Python :: python order number list 
Python :: nth catalan number 
Python :: Python RegEx re.compile() 
Python :: pandas fillna multiple columns 
Python :: class decorator python 
Python :: python print int operations 
Python :: Random Colored Shapes with python turtle 
Python :: mean squared error in machine learning formula 
Python :: upgrade python version windows 
Python :: gui button in tkinter color 
Python :: flask form options 
Python :: .squeeze function in numpy 
Python :: how to read specific words from a file in python 
Python :: for loop in python 
Python :: pandas save dataframe with list 
Python :: simple bmi calculator using python 
Python :: list add pythhon 
Python :: duplicate remove 
Python :: install python anaconda 
Python :: immutability in python 
Python :: f string 
Python :: bresenham circle drawing algorithm 
Python :: how to load a keras model with custom loss function 
Python :: firestore search query flutter 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =