0% found this document useful (0 votes)
42 views7 pages

4 SC

This document contains the source code and input/output screenshots for 10 NumPy programs completed as part of a Tool & Technique Laboratory (T&T Lab.) course. The programs cover tasks such as concatenating arrays, splitting arrays by spaces, finding indexes of substrings, counting occurrences of words, calculating max/min along axes, deleting/inserting columns, reshaping arrays, generating random integers, replacing odd numbers with -1, and creating an integer array with a specified difference between elements.

Uploaded by

SABYASACHI SAHOO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views7 pages

4 SC

This document contains the source code and input/output screenshots for 10 NumPy programs completed as part of a Tool & Technique Laboratory (T&T Lab.) course. The programs cover tasks such as concatenating arrays, splitting arrays by spaces, finding indexes of substrings, counting occurrences of words, calculating max/min along axes, deleting/inserting columns, reshaping arrays, generating random integers, replacing odd numbers with -1, and creating an integer array with a specified difference between elements.

Uploaded by

SABYASACHI SAHOO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

T&T Lab.

(CS-3096), Spring 2023

Tool & Technique Laboratory (T&T Lab.)


[CS-3096]
Individual Work
Lab. No:7 , Date:24/3/2023 , Day: Friday
Topic: NumPY
Roll Number: 2006189 Branch/Section: IT-3
Name in Capital: SABYASACHI SAHOO

Program No: 7.1

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 No: 7.2

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

array = np.array(['DBMS OOPS DS'], dtype=np.str)


print(array)

sparr = np.char.split(array)
print(sparr)

Program No: 7.3

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 No: 7.4

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

str1 = np.array([['cat ','cat ','bat'],


['sat','bat','cat'],
['sat','mat','cat']])
print("Original array of string values:")
print(str1)
print("NO OF CAT=")
print(np.char.count(str1, 'cat'))

Program No: 7.5

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

arr = np.array([[34, 43, 73],


[82, 22, 12],
[53, 94, 66]])
Page
T&T Lab.(CS-3096), Spring 2023

min_axis_1 = np.min(arr, axis=1)


print("Printing amin of axis 1:", min_axis_1)

max_axis_0 = np.max(arr, axis=0)


print("Printing amax of axis 0:", max_axis_0)

Program No: 7.6

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

original_arr = np.array([[34, 43, 73],


[82, 22, 12],
[53, 94, 66]])

print("Printing Original array: ")


print(original_arr)

Page
T&T Lab.(CS-3096), Spring 2023

new_arr = np.delete(original_arr, 1, axis=1)

print("Array after deleting column 2 on axis 1: ")


print(new_arr)

new_column = np.array([10, 10, 10])

new_arr = np.insert(new_arr, 1, new_column, axis=1)

print("Array after inserting column 2 on axis 1: ")


print(new_arr)

Program No: 7.7

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 No: 7.8

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 No: 7.9

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 No: 7.10

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

x = numpy.arange(100, 200, 10)


x = x.reshape(5,2)
print (x)

Page

You might also like