To introduce you with python programming language ,opencv and numpy.
How to Installation:
Download and install Python interpreter and PyCharm IDE from the following links below.
Python interpreter: https://www.python.org/downloads/
PyCharm IDE: https://www.jetbrains.com/pycharm/download/downloadthanks.html?platform=windows&code=PC
Setup for creating new project in python:
1. Create ‘New Project’
2. Now Check ‘Existing interpreter’ and Add local python interpreter that you’ve installed, and click Create.
How to Install OpenCv :
Some of task for the practice:
Practice Task 1:
(a)
Code
import numpy as np
x = [[1, 2, 3, 4, 5], [21, 22, 23, 24, 25], [31, 32, 33, 34, 35]]
print(x[1][3:5])
print(x[0][2:4])
print(x[2][1:2])
print(x[1][0:5:2])
OUTPUT:
(b)
Code:
x = [[1, 2, 3, 4, 5], [21, 22, 23, 24, 25], [31, 32, 33, 34, 35]]
y = [0, 0, 0]
lists = len(x) #number of lists
#nester for loop
for i in range(lists):
elements = len(x[i]) #number of elements in each list
for j in range(elements):
y[i] = y[i]+x[i][j]
y[i] = y[i]/elements #calculate average
print(y)
Output:
Practice Task 2:
Code:
x=['abc','1121', 'mnnm' , 'aba']
length = len(x) #number of strings in x
string_count = 0 #initialize counter
for i in range(length): #for each string in x
elements = len(x[i]) #number of elements in each string
if x[i][0]==x[i][-1]: #check if frist and last elements are equal
string_count = string_count + 1 #increment counter
print('String count is : ', string_count) #print string count
Output:
String count is : 3
Practice Task 3:
Write a function which takes a list as input argument and generate a new list after removing the 0 th , 3 th and 5 thindex value of list. x=[‘apple’, ’banana’, ‘mango’, ‘orange’, ‘peach’ , ‘grapes’] Output of this function:x=[’banana’, ‘mango’, ‘peach’]
Code:
x = ['apple', 'banana', 'mango', 'orange', 'peach' , 'grapes']
x.__delitem__(5)
x.__delitem__(3)
x.__delitem__(0)
print('New List is : ', x) #print new list
Output:
No comments:
Post a Comment