Question

How would I use Numpy in python to search in arr2 with arr1 and return the...

How would I use Numpy in python to search in arr2 with arr1 and return the string value.
arr1=[0,a],[1,b],[2,c]

arr2=[2],[1],[0]

Expected outcome is =[c],[b],[a]
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import numpy as np
a1=np.array([[0,'a'],[1,'b'],[2,'c']])
a2=np.array(([[2],[1],[0]]))
a2=np.squeeze(a2) .....# to make use to search
out= a1[a2][:,1] ...#to get string
out

output:-

[c],[b],[a]

To get the desired result we need to squeeze the a2 to search in a2 with a1

Add a comment
Know the answer?
Add Answer to:
How would I use Numpy in python to search in arr2 with arr1 and return the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi. It's a python and I got an error below comment import numpy as np arr=np.genfromtxt("/Volumes/Samsung...

    Hi. It's a python and I got an error below comment import numpy as np arr=np.genfromtxt("/Volumes/Samsung SSD 860 EVO 500GB Media/Download/primenumbers.txt", dtype=int) arr=arr.reshape(-1,1) arr.shape def find_cat(x): if x<= 300: return '<=300' elif x <= 600: return '<=600' else: return '<=1000' arr2 = np.apply_along_axis(find_cat, axis=1, arr=arr) arr2 = arr2.reshape(-1,1) arr3 = np.hstack((arr, arr2)) arr_300 = np.array((col[0] for col in arr3 if col[i]=='<=300'), dtype=int) arr_300 arr_300.shape count_300=len(arr_300) count_300 avg_300=round(np.mean(arr_300, 2) avg_300 print("Number of items in category \ "<=300\"= (one), and average of...

  • In python using numpy and for loops. How would I insert a multidimensional array into another...

    In python using numpy and for loops. How would I insert a multidimensional array into another multidimensional array, multiple times. For example if I defined A = [[1,2],[3,4]] and B as a four by four matrix of zeros, How would I insert A into B such that when I print B I get, [[1,2,1,2],[3,4,3,4],[1,2,1,2],[3,4,3,4]]

  • Given below is a partially completed C program, which you will use as a start to...

    Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count - @; for (int i = 0; i < SIZE; i++) { if (arri[i] > arr2[i]) count++; return count; Task 1: (10 pts) Show the design of the function compareAndCount() by writing a pseudocode. To...

  • PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Given...

    PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = 0; for (int i = 0; i < SIZE; i++) { if (arri[i] > arr2[i]) count++; } return count;...

  • PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint:...

    PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint: the number array in task 2 is work for task 3 in figure 1.   Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = 0; for (int i...

  • I need to make this code access the main method I suppose, but I don't know...

    I need to make this code access the main method I suppose, but I don't know how to make that happen... Help please! QUESTION: Write a method called switchEmUp that accepts two integer arrays as parameters and switches the contents of the arrays. Make sure that you have code which considers if the two arrays are different sizes. Instructor comment: This will work since you never go back to the main method, but if you did, it wouldn't print out...

  • I want to use BING API for web searching using python. Search result should only contain PDF. I a...

    I want to use BING API for web searching using python. Search result should only contain PDF. I added the advanced operator (filetype: pdf) in the search query. But seems it not working. ******** Python code ************** import requests def bing_search(query): url = 'https://api.cognitive.microsoft.com/bing/v5.0' # query string parameters payload = {'q': query, 'filetype':'pdf','responseFilter':'Webpages'} # custom headers headers = {'Ocp-Apim-Subscription-Key': '9126a2280100424b90b85d764a18dc34'} # make GET request r = requests.get(url, params=payload, headers=headers) # get JSON response return r.json() j = bing_search('Machine Learning') print(j.get('webPages',...

  • Your goal is to create an ‘Array’ class that is able to hold multiple integer values....

    Your goal is to create an ‘Array’ class that is able to hold multiple integer values. The ‘Array’ class will be given functionality through the use of various overloaded operators You will be given the main() function for your program and must add code in order to achieve the desired result. Do not change any code in main(). If something is not working, you must change your own code, not the code in main(). Assignment 5: overloading member functions. Overview:...

  • please answer this c++ question if you know all the questions not just some of them ... thanks Problem 4: Rewrite the f...

    please answer this c++ question if you know all the questions not just some of them ... thanks Problem 4: Rewrite the following function so that it can operate on arrays of any data type, not just integers. You may assume that all operations and comparisons are defined for all data types that we would pass into this function: int cloneArrayReturnMax(int* arr1, int size1, int* arr2, int size2) { size1 int end size2 if (end > size2) end for (int...

  • Write a function in python, index(arr, value) to find indices of elements equal to some value...

    Write a function in python, index(arr, value) to find indices of elements equal to some value in a Numpy array. The input arr is a 1-d numpy array, and input value is the value to search for. The function should return the index of the value. If the value occurs for multiple times, then all the indices should be returned as a 1-d numpy array. For example, if arr=[1 0 2 0 3 0 4 0 5 0 6 7...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT