4 SC
4 SC
Program Title:
Write a NumPy program to concatenate element-wise two arrays of string.
Input/Output Screenshots:
RUN-1:
Source code
import numpy as np
print("Concatenation")
print(np.char.add(['I am','a'], [' student', ' of kiit'] ))
Program Title:
Write a NumPy program to split the element of a given array with spaces.
Input/Output Screenshots:
RUN-1:
Page
T&T Lab.(CS-3096), Spring 2023
Source code
import numpy as np
sparr = np.char.split(array)
print(sparr)
Program Title:
Write a NumPy program to count the lowest index of "P" in a given array, element-wise.
Input/Output Screenshots:
RUN-1:
Source code
import numpy as np
x1 = np.array(['Python', 'Para', 'Java', 'pomegranate', 'pasta'], dtype=np.str)
print("\nOriginal Array:")
print(x1)
print("count the lowest index of ‘P’:")
r = np.char.find(x1, "P")
print(r)
Program Title:
Write a NumPy program to count a given word in each row of a given array of string values.
Input/Output Screenshots:
RUN-1:
Page
T&T Lab.(CS-3096), Spring 2023
Source code
import numpy as np
Program Title:
WAP to print max from axis 0 and min from axis 1 from the following 2-D array.
Input/Output Screenshots:
RUN-1:
Source code
import numpy as np
Program Title:
WAP to delete the second column from a given array and insert the following new column in its
place.
Input/Output Screenshots:
RUN-1:
Source code
import numpy as np
Page
T&T Lab.(CS-3096), Spring 2023
Program Title:
WAP to Convert a 1-D array into a 2-D array with 3 rows
Input/Output Screenshots:
RUN-1:
Source code
import numpy as np
arr = np.array([0,1,2,3,4,5,6,7,8])
print(arr)
arr = arr.reshape(3,3)
print(arr)
Program Title:
WAP to generate a 1-D array of 10 random integers. Each integer should be a number between 30
and 40 (inclusive).
Page
T&T Lab.(CS-3096), Spring 2023
Input/Output Screenshots:
RUN-1:
Source code
import numpy as np
x = np.random.randint(low=30, high=40, size=10)
print(x)
Program Title:
WAP to Replace all odd numbers in the given array with -1.
Input/Output Screenshots:
RUN-1:
Source code
import numpy as np
x = np.array([ 11, 12, 13, 14, 15, 16, 17, 18, 19, 10])
x[x%2==1] = -1
print (x)
Program Title:
WAP to create a 5X2 integer array from a range between 100 to 200 such that the difference
between each element is 10.
Page
T&T Lab.(CS-3096), Spring 2023
Input/Output Screenshots:
RUN-1:
Source code
import numpy
Page