# Create a list of vectors my_list <- list(a = c(1, 2, 3), b = c(4, 5, 6), c = c(7, 8, 9)) # Add a new vector my_list$d <- c(10, 11, 12) # Remove an element my_list$b <- NULL # Modify an element my_list$a <- c(100, 200, 300) print(my_list)
def calculator(a, b, op): if op == '+': return a + b elif op == '-': return a - b elif op == '*': return a * b elif op == '/': return a / b else: return "Invalid operation" a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) op = input("Enter operation (+, -, *, /): ") print("Result:", calculator(a, b, op)) 5a. R: Create a 3x3 Array from Two Vectors: # Vectors vec1 <- c(1, 2, 3, 4, 5, 6) vec2 <- c(7, 8, 9, 10, 11, 12) # Create a 3x3 array array <- array(c(vec1, vec2), dim = c(3, 3, 2)) print(array)
5b. OpenCV: Rotate Image by Specific Angles:
import cv2 import numpy as np # Load the image image = cv2.imread("input.jpg") def rotate_image(img, angle): h, w = img.shape[:2] center = (w // 2, h // 2) matrix = cv2.getRotationMatrix2D(center, angle, 1.0) return cv2.warpAffine(img, matrix, (w, h)) # Rotate and display images angles = [60, 110, 155] for angle in angles: rotated = rotate_image(image, angle) cv2.imshow(f"Rotated by {angle} degrees", rotated) cv2.waitKey(0) cv2.destroyAllWindows() 6a. OpenCV: Write Text on Image: image = cv2.imread("input.jpg") # Write text cv2.putText(image, "Hello, OpenCV!", (50, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2) # Display result cv2.imshow("Image with Text", image) cv2.waitKey(0) cv2.destroyAllWindows()