Answer to Question #314311 in Python for xxx

Question #314311

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]])


1
Expert's answer
2022-03-19T19:25:36-0400

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]

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS