Question

Hi i'd like to get a source code in Python. /* Use a mask to multiply...

Hi i'd like to get a source code in Python.

/*

Use a mask to multiply all values below 100 in the following list by 2:

>>> a = np.array([230, 10, 284, 39, 76])

Repeat this until all values are above 100. (Not manually, but by looping) Then, select all values between 150 < a < 200.

*/

Thank you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

OUTPUT :

CODE :

import numpy as np
#Given numpy array
a = np.array([230, 10, 284, 39, 76])
#Find the mask for all elements less than 100
mask = (a<100)
#Keep checking if length of mask is greater than zero
while sum(mask)>0:
#Multiply masked elements by 2
a[mask] = a[mask]*2
#Find mask again
mask = (a<100)
#Select elements such that 150<a<200
print(a[a>100][a<200])

Add a comment
Know the answer?
Add Answer to:
Hi i'd like to get a source code in Python. /* Use a mask to multiply...
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, I need help writing a code for this. The language is python 3, and we...

    Hi, I need help writing a code for this. The language is python 3, and we cannot use things like break, continue, exit(), lambda, map, filter, raise, try, except, and assert in our code. Thank you! Implement one of the sorting algorithms from class, either bubble, selection or quick sort with the following modification. Call the function "color_sort(the_list)" Each element is now a list (or tuple) with two elements. The first element is the number value that you need to...

  • Hi, I need some help finishing the last part of this Python 1 code. The last...

    Hi, I need some help finishing the last part of this Python 1 code. The last few functions are incomplete. Thank you. The instructions were: The program has three functions in it. I’ve written all of break_into_list_of_words()--DO NOT CHANGE THIS ONE. All it does is break the very long poem into a list of individual words. Some of what it's doing will not make much sense to you until we get to the strings chapter, and that's fine--that's part of...

  • Python please help! Thanks you Write a code to get an unlimited number of grades from...

    Python please help! Thanks you Write a code to get an unlimited number of grades from the user (the user can press enter to finish the grades input, or use a sentinel, for example-1), and then calculate the GPA of all the grades and displays the GPA To do this you might need some help. Try to follow the following process (and check your progress by printing different values to make sure they are as they supposed to be): 1-...

  • This needs to be written in Python. I'm writing this but I'd love to see how...

    This needs to be written in Python. I'm writing this but I'd love to see how others would do it. I have idea to make a program to keep track of reading. Set goal per day. Input minutes per day & book read. Could accumulate for whole month. Input daily, but you can input it all at the end of the week if you want. I want the user to be prompted to enter a numerical value and book for...

  • given code: assignment: use python to extend the given code to create an output similar to...

    given code: assignment: use python to extend the given code to create an output similar to the one in the black box please explain the final code import random HALMst N in = int(input('Enter Total Number of Cards: ") NM in NOON A = [] B [] E - [] D = [] E = [] for i in range(1, n+1): A.append(i) D.append(i) E.append(i) for j in range(n): 8.append(random.choice(D)) D.remove(B[5]) C.append(random.choice(E)) E.remove(C[j]) c= 0 for k in range(n): if (Brkl...cikl):...

  • hi which code should I use to get the following matrix and be able to change...

    hi which code should I use to get the following matrix and be able to change the number of rows. the code in the picture doesn't work for me for some reason. thank you. I use matlab program it needs to look like this and be a 10 by 10 matrix. 40 SC Matrix C sym (zeros) C(1,1) = 1; tsets the element 1,1 to be egy 42 - 44 - 45 - 46 - for n = 2:N starts...

  • USE Python 2.7(screen shot code with indentation and output exactly in the question) the task is:...

    USE Python 2.7(screen shot code with indentation and output exactly in the question) the task is: takes in a list of protein sequences as input and finds all the transmembrane domains and returns them in a list for each sequence in the list with given nonpolar regions and returns the lists for those. 1. This code should call two other functions that you write: regionProteinFind takes in a protein sequence and should return a list of 10 amino acid windows,...

  • NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work...

    NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work with lists Work with lists in functions Work with files Assignment: Part 1: Write a program to create a text file which contains a sequence of test scores. Ask for scores until the user enters an empty value. This will require you to have the scores until the user enters -1. After the scores have been entered, ask the user to enter a file...

  • in python and can you tell me why i am wrong? Thank you ZyBooks Python M...

    in python and can you tell me why i am wrong? Thank you ZyBooks Python M X zy cS 171: Computer x zy 11.9. LAB: Output x C Write A Program 1 x Slack | Hiu Nguy TG Python Program t x p ython - Getting x +. - 5 x € → e l earn.zybooks.com/zybook/DREXELCS171 Winter2020/chapter/11/section/9 Help/FAQ Kuanyu Lai - = zyBooks Bake My library > CS 171: Computer Programming home> > 11.9: LAB: Output values in a list...

  • Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture...

    Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture is to be made. def load_locations(filename): (str) -> dict Read data from the file with the given fi lename and create and return a dictionary with location data, structured as descr ibed in the ass ignment handout, Part 1 Section I1 [BEGIN DESCRIPTION There is nothing interesting here [END DESCRIPTION] BEGIN DESCRIPTION] You wake up lost in some unfamiliar place. All you know is...

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