Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Python #NumPy #insert #Function #Example #Working #arrays
ADD COMMENT
Topic
Name
5+6 =