Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a python 3 to solve this problem, thanks Cartesian Product Programming challenge description: The Cartesian product of two lists of numbers A and B
Write a python 3 to solve this problem, thanks
Cartesian Product Programming challenge description: The Cartesian product of two lists of numbers A and B is defined to be the set of all points (a,b) where a belongs in A and b belongs in B. It is usually denoted as A x B , and is called the Cartesian product since it originated in Descartes' formulation of analytic geometry. Given two sets of real numbers, their Cartesian product comes in form of ordered pairs. e.g. A = [1, 2, 3] [4, 5] B = Cartesian product is = C = [(1, 4), (1, 5), (2,4), (2.5), (3, 4), (3,5)] Now given a coordinate tuple (i,j), where i indicates A[i] and j indicates B[j] with A, B known, implement a function that returns the index of a member in Cartesian product Caccording to (i,j) For example: coordinate (1, 0) return index: 2 coordinate (2, 1) return index: 5 The time complexity of this algorithm should be 0(1) Input: real number set A real number set B coordinate tutple (i, j) Output: Index of a member in AX B (Cartesian product of A and B) If inputs are invalid, return -1 Test 1 Test Input [1, 2, 3] [4, 5] (1, 0) Expected Output 2 Test 2 Test Input [1, 2, 3] [4, 5] (2, 1) Expected Output 5 Test 3 Test Input ['a', 'b', 'c'] [1, 2,3] , (0, 1) Expected Output 6 -1 1 import sys 2 # import numpy as np 3 # import pandas as pd 4 # from sklearn import 5 6 for line in sys.stdin: 7 print(line, end="") 8Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started