Python function getData(fname:str)->ndarray that inputs data from a file into a list, then converts the list to a NumPy array of integer values and returns the array. The text file (fname) contains: integer numbers, one per line numbers are in the range 0 <= n <= 99 r * c (rows * columns) quantity of numbers, where c = r + 1
Q: onsider an input string TAM of letters ‘A’, ‘M’, and ‘T’. This string, which is given by the user,…
A: We are given a string, combined of the letters A, M and T. We have to sort that string using the the…
Q: 2. An ascending array is an array such as “124678", “abcfgkl", and “5789", that every character is…
A: Program Approach: If the array is empty or array size is 1 return true. If the last two elements…
Q: 11.13 (Python please) Locate the largest element) Write the following function that returns the…
A: The python program text and the formatted image version are given below: def locateLargest(a):…
Q: 1. Write a function that takes two arrays which are already ordered (in ascending order) and creates…
A: Actually, program is an executable software that runs on a computer.
Q: Modify selection_sort.c so that it includes the following functions: void selection_sort(int "a, int…
A: Here is the solution:-
Q: def second largest(lst: List[int]) -> int: Given a list of integers, return the second largest item…
A: This is very simple you can use same concept as we use in finding greatest no Check if current no…
Q: python" Write a function named add_value that has a single parameter. This parameter will be a…
A: start define a function that takes list as a parameter append 21 in list stop
Q: email address, birthday, etc. Write a program that first takes as input an integer N that represents…
A: Code: import java.util.Scanner; class Main{ public static String getPhoneNumber(String[]…
Q: lay the sorted list. Another function should be called that calculates the average score and display…
A: Code: #include<iostream>using namespace std;int n; //global variable for number of…
Q: Generate the code for a function: findBig(a: Ndarray) --> list The function searches the contents of…
A: Python program to solve the given problem is below.
Q: JAVA Problem Create a function that determines whether elements in an array can be re-arranged to…
A: Given Like arr[]=[5,1,4,3,2]-->true as it can be arranged like 1,2,3,4,5 arr[]=5,1,4,3,2,8]-->…
Q: 1. Write a function named "isBoundedArray" that accepts an array of integers and its size. The…
A: For Q1) , I have provided C CODE along with CODE SCREENSHOT and 3 output…
Q: Create a Python file and begin with this code: FUNCTION DEFINITIONS def main(): *Create a list cats…
A: Based on Python
Q: C++ Create a generic function: print_if(start, stop, condition, out) that prints to output stream…
A: Solution -
Q: The code of a sequential search function is shown on textbook page 60. In fact, if the list is…
A: """Program to seach target element in list""" #function to search target in listdef…
Q: Language: Python 3 • Autocomplete Ready O 1 v import ast 3. Hybrid Sort lst = input() lst =…
A: We can use binary search to reduce the number of comparisons in normal insertion sort. Binary…
Q: able to keep track // frequency of copy operation (marked below), an
A: The code is shown as,
Q: C++ Create a function append(v, a, n) that adds to the end of vector v a copy of all the elements…
A: // C++ code to demonstrate copy of vector// by iterative…
Q: Write the remove_evens() function, which receives a list of integers as a parameter and returns a…
A: Use another list in the function where we append only the odd numbers to the list and return the…
Q: (PYTHON) Please include what is given below in the final code. Thank you! The list method reverse…
A: Given: PYTHON) Please include what is given below in the final code. Thank you! The list method…
Q: Assume that you have a student list of this class which list consists of only student names. Your…
A: I have taken 10 student names assuming each length is less than 10 characters as shown below. I used…
Q: Flowchart, create. Passing Lists to Functions in Python def reverseArray(array): for i in…
A: Given Python program contains a function reverseArray() and this takes an array as input. Then for…
Q: use C programming to solve the question. make sure the output is working and use comments. thank you
A: Approach: Include necessary header files In the main function declare the 2D array that holds the…
Q: 1. Sorting • Begin by filling an array with random numbers: import numpy as np np.random.seed(1012)…
A: Array An array is a set of related data elements kept in close proximity to one another in memory.…
Q: In statistics the median of a set of values is the value that lies in the middle when the values are…
A: Code: #include<iostream>using namespace std;double med(int* arr, int size){double result =…
Q: Hello! Any help with this question would be great appreciated! If you could include screenshots on…
A: Note: we are only allowed to solve one question in one post. to get answers to others, please post…
Q: def create_identity_matrix(n): """ Create a nxn sized identity matrix. The return type should be a…
A: def create_identity_matrix(n): identity_matrix=[] temp=[] # uses nested loop to…
Q: Write a function that accepts a list as an argument (assume the list contains integers) and returns…
A: def getTotal(list): total = 0 for item in list: total = total + item return total
Q: Write a program that reads an integer, a list of words, and a character. The integer signifies how…
A: #include <iostream>#include <string>using namespace std; int main(){string word[100];int…
Q: #include using namespace std; // Function to return a vector that contains // all the generated…
A: It is defined as direct descendant of C programming language with additional features such as type…
Q: 1. Write function that swaps the values of two integer variables a. using pass by value and b. pass…
A: 1. a. The function to swap two integers by passing the values is shown below. void swap(int x, int…
Q: Write a function maxSpan(vector) measures the span between the smallest and largest integers in an…
A: #include <vector>#include <algorithm>using namespace std; public int maxSpan(int[]…
Q: hat does the following statement do? Assume that vec is a vector of integers. vec.insert(vec.begin()…
A: C++ programming language supports STL(Standard template Libraries) in which vector is a template…
Q: def second_largest(lst: List[int]) -> int: """ Given a list of integers, return the second…
A: Write a python code that will return the second largest element in an integer list. Complete the…
Q: Input: 1 1 6 3 8 4 2 3 9 2 4 Output: 1 Selection Sort 2 1 6 3 8 4 2 3 9 2 4 3 1 2 3 8 4 6…
A: Solution: For each of the three sorting algorithms (selection, insertion, and bubble), your…
Q: 1. A list of numbers is said to be balanced if the sum of its first half is equal to the sum of its…
A: As per our company guidelines we are supposed to answer only one question per post and kindly…
Q: o sorted array-based lists into one sorted array-based list. The function takes two arrays as…
A: Step 1: Here is the completed code for this problem. Comments are included, go through it, learn…
Q: 15: points.cpp) Write a program that reads 10 pairs of rtesian coordinates from a file called…
A: Actually, c++ is a general purpose language.
Q: Question 3: r" An array listA is called balanced if it stores the same count of even and odd…
A: Step-1: Start Step-2: Declare and input an array 'listA' of size 10 Step-3: Print array listA…
Q: Question1: define two lists of numbers (arrays) and ask the user to give the size of each, and then…
A: First check whether the lengths are same or not Then every element in both the arrays and check…
Q: C++ Problem!! Sort A List Of Integers Given a file of 100,000 unsorted integers, write a program…
A: According to the information given:- We have to follow the instruction to compute as mentioned.
Q: (c) A palindromic number is a number that is the same if read forwards or backwards: 12321 and…
A: Palindrome number is a number which is read same from backwards as well as front. It means reverse…
Q: ere is the code for number 1. def reverse_list(old_list): new_list = [ele for ele in…
A: Note: we are only allowed to solve one question in one post. Since first is already solved, I am…
Q: interleaved Write a function interleaved that accepts two sorted sequences of numbers and returns a…
A: #function interleaved takes two sorted lists, then returns a sorted sequence of all numbers by…
Q: Assume that you have a student list of this class which list consists of only student names. Your…
A: In step 2 you will get the C code and in step 3 you can see the output. I have used 2-dimensional…
Q: #include using namespace std; #define SIZE 10 void main () int i, number[SIZE], sum; sum = 0; for…
A: #include <iostream>#include <fstream>using namespace std;#define SIZE 10int main(){…
Q: Python Programming PART A Write the code for a Python function named "loadData" that accepts 2…
A: Input : List named alpha List named alphaCodes Output : Dictionary where the key is alpha and…
Q: 8.13 LAB: Library book sorting Two sorted lists have been created, one implemented using a linked…
A: Actually, arrays are two types: i)sorted array ii) unsorted array
Q: urpose: To practice reading from a tabular file to a simple dictionary Degree of Difficulty: Easy.…
A: EXPLANATION: fnReadInParameters(filepath): Is a function that takes FILEPATH as a parameter and…
Q: main.cpp x //Given a list of numbers find the largest and the smallest values of the list and…
A: Sample Output
Python function getData(fname:str)->ndarray that inputs data from a file into a list, then converts the list to a NumPy array of integer values and returns the array.
The text file (fname) contains:
- integer numbers, one per line
- numbers are in the range 0 <= n <= 99
- r * c (rows * columns) quantity of numbers, where c = r + 1
Example:
15
22
65
4
78
91
7
35
60
16
99
12
==
[[15 22 65 4]
[78 91 7 35]
[60 16 99 12]]
Step by step
Solved in 2 steps
- python wirte a function max_indexes(xs) that inserts a list xs with numbers and returns a list of indexpositions where the list has local maximum values. A local maximum value is a number in the list that has a smaller number before and after. for example in this list has a local maximum at position 2 and 7: [3, 4, 5, 2, 1, 0, 4, 6, 4, 2, 1] Here the function should return [2, 7]#### Part 1 Write a Python function (`insertion_sort`) that implements the insertion sort algorithm, discussed in the lectures. This function will take exactly one list argument, and will return a list. The argument (`values`) is a list of integers to be sorted. You will return a new list which has been sorted in ascending order. Below, you will find some code to test your insertion sort: ```python unsorted = [4,3,7,1,8,2] sorted = insertion_sort(unsorted) print(sorted) ``` #### Part 2 Modify your `insertion_sort` function to count the number of comparisons (==, <, <=, >, or >=). The function will now return both the number of comparisons made and the sorted list (in that order). _**Note:** For simplicity, since counting these comparisons won't improve the accuracy of your count very much, we'll ignore the comparisons made in the final iteration of the loop. One or both of these comparisons may actually be made, so determining the exact number of comparisons would be….......Python Code............. Python file: # Write a function that takes an open hockey file and returns a list of tuples,# where each tuple refers to a team name and that team's maximum number of wins in any year. from typing import TextIO def teams_and_most_wins(f: TextIO) -> list[tuple[str, int]]: # Return a list of tuples where each tuple stores a team name and # that team's maximum number of wins in any year. # DO CODE HERE ... Use this '''f is an open hockey file.Each year has 4 digits and each number of wins has 2 digits.Every team should appear in exactly one of the tuples.''' .......File............. Each line of a hockey file contains a four-digit year, a team name, and a two-digit number of wins.Here is one such file, hockey.txt:>>>2003maple leafs452020maple leafs351995senators181996maple leafs302000senators482012canadiens48>>>The first line of the file, for example, says that in 2003 (year), the maple leafs (team…
- 22.3 LAB: Remove all even numbers from a list (Use Python) Write the remove_evens() function, which receives a list of integers as a parameter and returns a new list of integers containing only the odd numbers from the original list. The main program outputs values of the returned list. Hint: If the original list has even numbers, then the new list will be smaller in length than the original list and should have no blank elements. Ex: If the list passed to the remove_evens() function is [1, 2, 3, 4, 5, 6, 7, 8, 9], then the function returns and the program output is: [1, 3, 5, 7, 9] Ex: If the list passed to the remove_evens() function is [1, 9, 3], then the function returns and the program output is: [1, 9, 3]#### Part 1 Write a Python function (`binary_search`) that implements the binary search algorithm. This function will take a list argument (`values`), a value to search for (`to_find`), a start index (`start_index`), and an end index (`end_index`). The function will return `True` if `to_find` is present in `values`, and `False` otherwise. Below, you will find some code to test your binary search: ```python values = [2,4,6,8,10,12,14,16,18,20] print(binary_search(values, 14, 0, len(values) - 1)) print(binary_search(values, 7, 0, len(values) - 1)) ``` The output of the test code is below: ``` True False ``` #### Part 2 Modify your `binary_search` function to count the number of comparisons (==, <, <=, >, or >=). The function will now return both the number of comparisons made and the `True` or `False` result. The code below calls your function, and creates a simple ASCII bar chart of the number of comparisons (divided by 10, to account for small differences). Some…TROUBLESHOOT my PYTHON code, please :) The code of a sequential search function is shown on textbook page 60. In fact, if the list is already sorted, the search can halt when the target is less than a given element in the list. For example, given my_list = [2, 5, 7, 9, 14, 27], if the search target is 6, the search can halt when it reaches 7 because it is impossible for 6 to exist after 7. Define a function linearSearchSorted, which is used to search a sorted list. This function displays the position of the target item if found, or 'Target not found' otherwise. It also displays the elements it has visited. To test your function, search for these targets in the list [2, 5, 7, 9, 14, 27]: 2, 6, 14, 27 and 28. Expected output: List: [2, 5, 7, 9, 14, 27] Search target: 2 Elements visited: 2 Target found at position 0 Search target: 6 Elements visited: 2 5 7 Target not found Search target: 14 Elements visited: 2 5 7 9 14 Target found at position 4 Search target: 27 Elements visited: 2…
- Python Code Help Consider the following function and attempted body.""" from typing import TextIO def allergy_checker(shopping_lists: TextIO, clean_shopping_lists: TextIO, allergies: list[str]) -> None: ''' shopping_lists is a file open for reading that has at least one food name on every non-blank line. Food names are separated by a space. Each line in shopping_lists ends with a newline character. clean_shopping_lists is a file open for writing. allergies is a list of one-word food names. Copy lines from shopping_lists to clean_shopping_lists. For each food name that is in the allergies list, replace it with 'REMOVED'. If a blank line in shopping_lists is reached, stop reading the file. ''' shopping_lists = open(shopping_lists) # Line 1 clean_shopping_lists = open(clean_shopping_lists, 'w') # Line 2 line = shopping_lists.readline() # Line 3 while line.strip(): # Line 4 line = shopping_lists.readline() #…(Using Python)Write a function that returns a new list by eliminating theduplicate values in the list. Use the following function header:def eliminateDuplicates(lst):Write a test program that reads in a list of integers, invokes the function,and displays the result. Here is the sample run of the program Enter ten numbers: 2 3 2 1 6 3 4 5 2The distinct numbers are: 1 2 3 6 4 5Instructions are given within the quotations for each function. 1)def remove_duplicate_sorted(t): """ this function returns a new list generated from t that has t's elements without duplicates and is sorted from smallest to largest. """ return [] 2)def list_to_dictionary(t): """ t is a list of values (values could be str, list, tuple, set, dictionary), create and return a dictionary such that the key is len(v) for some v in t, and the value is a list of values [v1, v2, ...] from t (in the order they appeared in t) whose len(vi) is the key. for example: if t = [(1,2,3), "abc", [1, 2], (), ""] then return value of this function should be: {3: [(1, 2, 3), 'abc'], 2: [[1, 2]], 0: [(), '']} """ return {} 3)def run(): """ This function repeatedly ask user to enter a string and store them in a list and print it out. It also passes this list to remove_duplicate_sorted() function and list_to_dictionary() function and print out the results of the function calls. """ return if __name__ ==…
- Recursion and loops. Provide both recurrent and loop based implementation of the function count( e, L ) that returns the number of es in L, where L is a list. Also consider cases when L is an empty list. Create test cases and run driver, show how function runs in spyder (py file) or ipynb file. Submit code as a py or html or pdf files with screenshots of the runs.Please write it in Python Write a delete function that takes as an argument a list l and an elem element and returns the list obtained from l by deleting all occurrences of elem. Example: delete([4, 7, 12, 4, 4, 0, 4, 5], 4) return => [7, 12, 0, 5]. Write a function insere_milieu that takes as an argument a list l and an element elem and returns the list obtained from l by adding elem "in the middle" of l, that is: If the length of l is even, the item is added once, in the middle of the list. If the length of l is odd: the element is added on either side of the central element. Example: insere_milieu([4, 7, 12, 3], 0) return => [4, 7, 0, 12, 3] and insere_milieu([9, 3, 5, 6, 2], 1) return => [9, 3, 1, 5, 1, 6, 2]. Write a cutting function that takes as an argument a list of numbers l and a threshold number and returns two lists: the first is obtained from l keeping only the numbers below or equal to the threshold; the second is obtained from l keeping only the…Python Programming - (Duplicate Elimination) Part 1: Create a function that receives a list and returns a (possibly shorter) list containing only the unique values in sorted order. Test your function with a list of numbers and a list of strings. Program is to also display results, that's the sorted list containing values. Part 2: Instead of hard coding the list passed to the sorting functions, request list values from user. (Hint: Request two lists from user, one containing values and another containing string.) Have the program eliminate duplicated values and display the lists (tasks required in part 1).