human
Median of two sorted arrays of different sizes | Set 1 ( Linear ) | This function returns median of a [ ] and b [ ] . Assumptions in this function : Both a [ ] and b [ ] are sorted arrays.
Current index of i / p array a [ ].
Current index of i / p array b [ ].
Below is to handle the case where all elements of a [ ] are smaller than smallest ( or first ) element of b [ ] or a [ ] is empty.
Below is to handle case where all elements of b [ ] are smaller than smallest ( or first ) element of a [ ] or b [ ] is empty.
Below is to handle the case where sum of number of elements of the arrays is even.
Below is to handle the case where sum of number of elements of the arrays is odd.
Driver Code"
How can the above be solved in Python?
 Give me a code to median of two sorted arrays of different sizes and the other steps required?
assistant
#Here is code to median of two sorted arrays of different sizes and the other steps required.
 def findmedian ( a , n1 , b , n2 ) :
	j = 0
	m1 = - 1
	m2 = - 1
	for k in range ( ( ( n1 + n2 ) // 2 ) + 1 ) :
		if ( i < n1 and j < n2 ) :
			if ( a [ i ] < b [ j ] ) :
				m2 = m1
				m1 = a [ i ]
				i += 1
			else :
				m2 = m1
				m1 = b [ j ]
				j += 1
		elif ( i == n1 ) :
			m2 = m1
			m1 = b [ j ]
			j += 1
		elif ( j == n2 ) :
			m2 = m1
			m1 = a [ i ]
			i += 1
	if ( ( n1 + n2 ) % 2 == 0 ) :
		return ( m1 + m2 ) * 1.0 / 2
	return m1
if __name__ == " _ _ main _ _ " :
	a = [ 1 , 12 , 15 , 26 , 38 ]
	b = [ 2 , 13 , 24 ]
	n1 = len ( a )
	n2 = len ( b )
	print ( findmedian ( a , n1 , b , n2 ) )