Related questions
python: numpy
def purchases(transactions):
"""
QUESTION 7
- A high-end store is trying to evaluate the total amount that customer's spend per transaction. They
want customers to spend anywhere between 130ドル and 150ドル on average.
- You need to determine whether the average number spent on each transaction per month is above, between, or
below the desired amount.
- Transactions is a numpy array containing a date, total amount earned each month, and total
number of transactions each month.
- Above: month's average amount spent per transaction > 150
- Within Range: 150 >= month's average amount spent per transaction >= 130
- Below: month's average amount spent per transaction < 130
- Return a numpy array with "Above", "Within Range" and "Below" for the average amount spent per transaction per month
- THIS MUST BE DONE IN ONE LINE
HINT: use np.where() and convert the type of each column to float
Args:
transactions (np.array)
Returns:
np.array
>> transactions = np.array([['01-31-2022', 5462101, 24752],
['02-28-2022', 7081547.30, 34615],
['03-31-2022', 3287654.57, 16588],
['04-30-2022', 8725851.81, 45621],
['05-31-2022', 6730748.72, 26741],
['06-30-2022', 9562745.43, 76436],
['07-31-2022', 8641735.21, 61448],
['08-31-2022', 7641748.57, 52846],
['09-30-2022', 7645277.02, 65457],
['10-31-2022', 9416274.67, 65109],
['11-30-2022', 9841378.97, 57254],
['12-31-2022', 10654298.18, 98651]])
>> purchases(transactions)
['Above' 'Above' 'Above' 'Above' 'Above' 'Below' 'Within Range'
'Within Range' 'Below' 'Within Range' 'Above' 'Below']
"""
# transactions = np.array([['01-31-2022', 5462101, 24752],
# ['02-28-2022', 7081547.30, 34615],
# ['03-31-2022', 3287654.57, 16588],
# ['04-30-2022', 8725851.81, 45621],
# ['05-31-2022', 6730748.72, 26741],
# ['06-30-2022', 9562745.43, 76436],
# ['07-31-2022', 8641735.21, 61448],
# ['08-31-2022', 7641748.57, 52846],
# ['09-30-2022', 7645277.02, 65457],
# ['10-31-2022', 9416274.67, 65109],
# ['11-30-2022', 9841378.97, 57254],
# ['12-31-2022', 10654298.18, 98651]])
# print(purchases(transactions))
- Define a function "purchases" that takes in a numpy array "transactions" as input.
- Use np.where() to determine whether the average amount spent per transaction per month is "Above", "Within Range", or "Below".
- Convert the columns of the numpy array "transactions" to float using the astype() method.
- Calculate the average amount spent per transaction per month by dividing the total amount earned each month by the total number of transactions each month.
- Use np.where() to determine whether the average amount spent per transaction per month is "Above", "Within Range", or "Below" based on the desired range of 130ドル to 150ドル.
- Return a numpy array with the results.
Step by stepSolved in 4 steps with 2 images
- Task - Median elements (C Langugage) Given an array of integer elements, the median is the value that separates the higher half from the lower half of the values. In other words, the median is the central element of a sorted array. Since multiple elements of an input array can be equal to the median, in this task you are asked to compute the number of elements equal to the median in an input array of size N, with N being an odd number. Requirements Name your program project4_median.c. Follow the format of the examples below. The program will read the value of N, then read in the values that compose the array. These values are not necessarily sorted. The program should include the following function. Do not modify the function prototype. int compute_median(int *a, int n); a represents the input array, n is the length of the array. The function returns the median of the values in a. This function should use pointer arithmetic– not subscripting – to visit array elements. In other...arrow_forward1- Arrays can be created to store values of multiple data types at one place. True False 2- To copy the contents of one array to another you must copy the individual array elements. True Falsearrow_forward# Declare a named constant for array size here. MAX_AVERAGES = 8 # Declare array here. # Write a loop to get batting averages from user and assign to array. averageString = input("Enter a batting average: ") battingAverage = float(averageString) # Assign value to array. # Assign the first element in the array to be the minimum and the maximum. minAverage = averages[0] maxAverage = averages[0] # Start out your total with the value of the first element in the array. total = averages[0] # Write a loop here to access array values starting with averages[1] # Within the loop test for minimum and maximum batting averages. # Also accumulate a total of all batting averages. # Calculate the average of the 8 batting averages. # Print the batting averages stored in the averages array. # Print the maximum batting average, minimum batting average, and average batting average. This is on mindtap pyton what needs to be fixarrow_forward
- Module/Week 8 ASSIGNMENT Imagine you are using a two-dimensional array as the basis for creating the game battle- ship. In the game of battleship a '~' character entry in the array represents occan (i.e., not a ship), a `o character represents a place in the ocean where part of a ship is present, and a 'H' character represents a place in the ocean where part of a ship is present and has been hit by a torpedo. Thus, a ship with all 'H' characters means the ship has been sunk. Declare a two-dimensional array that is 25 x 25 that represents the entire ocean and an If statement that prints "HIT" if a torpedo hits a ship given the coordinates X and Y. Create a text file of 25 line. Each line has 25 characters. - represents water and # represents Then write a C++ program that will read in the file representing the game board with 25 lines where cach line has 25 characters corresponding to the description above. You must write a function called Fire() that will take an X and Y coordinate and...arrow_forwardThe logic will allow the user to: Load a single dimensional array of size 50 with a random number The random number will range from 1 to 1,000 (you may have duplicate values) Find the highest value and the index location that it was in Find the smallest value and the index location that it was in Display the array’s contents. Display the highest value and its index location Display the lowest value and its index location Allow the user to execute this application multiple times (some sort of loop?) You will need one for loop to load the array as well as one or two for loops to search that array. The rand also has a "nasty" tendency to create the same results repeatedly in an exe. To avoid that, we have to "shuffle the deck" every time. This ensures that all numbers are an equal probability of appearing and not the same set of values (would create a boring game). // Add this to "shuffle the deck" every time to ensure that // different values could occur else the exe produces the...arrow_forwardJAVA based programarrow_forward
- In visual basic Create an array that will hold 10 integer values.arrow_forwardProblem Description - JAVA PROGRAMMING Use a Two-dimensional (3x3) array to solve the following problem: Write an application that inputs nine numbers, each of which is between 1 and 10, inclusive. Display the array after the user inputs each value. Rotate/flip the array by changing places. Make the rows columns and vice versa. You have to move the elements to their new locations. Remember to validate the input and display an error message if the user inputs invalid data. Documentation and the screenshot(s) of the results. Example: 1 2 3 4 5 6 7 8 9 the result will be : 1 4 7 2 5 8 3 6 9arrow_forwardSultan Qaboos University Department of Computer Science COMP2202: Fundamentals of Object Oriented Programming Assignment # 2 (Due 5 November 2022 @23:59) The purpose of this assignment is to practice with java classes and objects, and arrays. Create a NetBeans/IntelliJ project named HW2_YourId to develop a java program as explained below. Important: Apply good programming practices: 1- Provide comments in your code. 2- Provide a program design 3- Use meaningful variables and constant names. 4- Include your name, university id and section number as a comment at the beginning of your code. 5- Submit to Moodle the compressed file of your entire project (HW1_YourId). 1. Introduction: In crowded cities, it's very crucial to provide enough parking spaces for vehicles. These are usually multistory buildings where each floor is divided into rows and columns. Drivers can park their cars in exchange for some fees. A single floor can be modeled as a two-dimensional array of rows and columns. A...arrow_forward
- Payroll Write a program that uses the following arrays: empId: an array of seven long integers to hold employee identification numbers. The array should be initialized with the following numbers: 5658845 4520125 7895122 8777541 8451277 1302850 7580489 hours: an array of seven integers to hold the number of hours worked by each employee payRate: an array of seven doubles to hold each employee's hourly pay rate wages: an array of seven doubles to hold each employee's gross wages The program should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the empId array. That same employee's pay rate should be stored in element 0 of the payRate array. The program should display each employee number and ask the user to enter that employee's hours and pay rate. It should then calculate the gross wages for that employee (hours times...arrow_forwardVisual basic 6.0arrow_forwardAlert dont submit AI generated answer.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education