7.Write a code to get the positions where elements of array a and array b are same
a = np.array(['a','b','c','b','c','d','c','d','e','f'])
b = np.array(['g','b','j','b','g','d','i','d','i','h'])
Answer:
Output:
(array([1, 3, 5, 7], dtype=int64),)
8.List the items which are present in array a but NOT present in array b
a = np.array(['a','b','c','d','e'])
b = np.array(['c','d','e','f','g'])
Answer:
array(['a', 'b'], dtype='<U1')
9.Reverse the sequence of rows in 2-D array
a = np.arange(16).reshape(4,4)
Answer:
Output:
array([[12, 13, 14, 15],
[ 8, 9, 10, 11],
[ 4, 5, 6, 7],
[ 0, 1, 2, 3]])
7.
c = []
def equal_index(a,b):
for i in range(len(a)):
if a[i] == b[i]:
c.append(i)
return np.array(c)
equal_index(a,b)
8.
c = []
def array_difference(a,b):
for element in a:
if element not in b:
c.append(element)
return np.array(c)
array_difference(a,b)
9.
a[::-1]
Comments
Leave a comment