Question

Assume that an array A is given to you in a txt file. You should read...

Assume that an array A is given to you in a txt file. You should read it. If you think this is a time-dependent data, print the number of local minimums in the array to a txt file. Local minimum means the element which is less than the previous element and the following element. Please do not use any additional library. For example, if A=[3, 2, 9, 8, 7, 8, 6], the code should print 2 and 7. (Local minimums are 2 and 7).

write in python .

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

#source code withiut using file:

data=[3,2,9,8,7,8,6]

local_minimum_count=0

for i in range(1,len(data)-1):

if(data[i-1]>data[i] and data[i+1]>data[i]):

local_minimum_count+=1

print(data[i])

print("local minimum count:",local_minimum_count)

#source code along with output:

1 N 3 Ою No Ол в 7 8 data=(3,2,9,8,7,8,6] local_minimum_count=0 for i in range(1, len (data)-1): if(data[i-1]>data[i] and dat

#using file

data.txt

3
2
9
8
7
8
6

1 2 3 4 5 6 3 2 9 8 7 8 6 7

#source code:

f=open("data.txt","r")

data=f.read().split("\n")

data=[int(i) for i in data]

local_minimum_count=0

for i in range(1,len(data)-1):

if(data[i-1]>data[i] and data[i+1]>data[i]):

local_minimum_count+=1

print(data[i])

print("local minimum count:",local_minimum_count)

1 2 3 4. 5 6 7 8 9 10 f=open(data.txt,r) data=f.read().split(\n) data=[int(i) for i in data] local_minimum_count=0 for

#if you have any doubt or more information needed comment below..i will respond as possible as soon..thanks..

Add a comment
Know the answer?
Add Answer to:
Assume that an array A is given to you in a txt file. You should read...
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
  • Write a C++ that read a list of numbers from a .txt file into array. The...

    Write a C++ that read a list of numbers from a .txt file into array. The first digit on the list will be array size, while the second number on the list will be our first number in our array list. Example: t1.txt file contain list off input number: 5, 3, 6, 10, 43, 23. notice the first number is 5 which will need to be use as an array size and the rest of the numbers are in the...

  • JAVA - Natural Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file...

    JAVA - Natural Quick Sort .txt and Return ----------------------------------------------------------------------------- The program should input a .txt file like below and must use a Quick sort Algorithm ================ 6 10 4 19 10 12 8 6 0 1 2 3 ================ The first number "6" represents the index of the element to return after sort the second number on the top "10" represents the number of elements or size of array. The following numbers and lines are the elements that need to...

  • Assume that you will be given a *.txt file, which in the same format of RandSource.txt...

    Assume that you will be given a *.txt file, which in the same format of RandSource.txt (attached). The file has three numbers at each line. Numbers are separated with a space. All number are in the range of [0, 50]. The first two numbers indicate a range. The third one shows number of random numbers to be generated in the range of first two numbers. The range always given in first < second order. If not, raise an error. For...

  • (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that...

    (IN PYTHON) You are to develop a Python program that will read the file Grades-1.txt that you have been provided on Canvas. That file has a name and 3 grades on each line. You are to ask the user for the name of the file and how many grades there are per line. In this case, it is 3 but your program should work if the files was changed to have more or fewer grades per line. The name and...

  • Write a java program to read from a file “input4_02.txt” an integer N (0? N ?...

    Write a java program to read from a file “input4_02.txt” an integer N (0? N ? 100) and then read N double numbers from this file to an array. Write to file “output4_02.txt” this array but in the reverse order and also the sum of all elements in the array. For example File: “input4_02.txt” 5 1.30 2.22 4.00 17.60 3.14 File “output4_02.txt” 3.14 17.60 4.00 2.22 1.30 Sum = 28.26

  • In C++, how would I read data from a .txt file into an array? For example,...

    In C++, how would I read data from a .txt file into an array? For example, I have an assignment that requires me to read temperatures from a file named data.txt into an array. How would I go about doing this?

  • IN JAVA Read the runners data file into arrays. ONE string array and ONE 2-dimension array....

    IN JAVA Read the runners data file into arrays. ONE string array and ONE 2-dimension array. Each runner has 8 pieces of data, which includes name, and how much they ran for each of 7 days. Print out the raw data in columns. Below the raw data, print out the total miles ran for all of the runners. THIS IS TXT FILE : Keith 10 8 4 5 12 3 2 Anna 9 8 7 6 5 12 13 Derick...

  • Read a file called populations.txt and populate a php associative array with the values read from...

    Read a file called populations.txt and populate a php associative array with the values read from the file. Here is an example populations.txt file: Dhaka, 23 million Bangaluru, 21 million New York, 9 million Emporia, 23 thousand Here's some pseudo code: open the file loop through the lines in the file read a line into a string variable explode (or is it split, or something else) the string into key value pairs save the key value pair into your associative...

  • using c and pointers only 1. You will read in two strings from a file cp4in_1.txt...

    using c and pointers only 1. You will read in two strings from a file cp4in_1.txt at a time (there will be 2n strings, and you will read them until EOF) and then do the following. You alternately take characters from the two strings and string them together and create a new string which you will store in a new string variable. You may assume that each string is no more than 20 characters long (not including the null terminator),...

  • Write a program to read a text file, place each line it reads into an array....

    Write a program to read a text file, place each line it reads into an array. Then print the array’s contents one line at a time. Then add to the end of the text file “Success”. Use error exception handling and if the text file does not exist print "Error file not found." Always print "It worked." as part of the try clause. Upload a zip folder file of the .py and text file. roses are roses are red, violets...

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
ADVERTISEMENT