Question: PYTHON QUESTION (6 points) The function os.listdir() returns a list of the names of files found in a directory. Suppose that L is the result

PYTHON QUESTION

(6 points) The function os.listdir() returns a list of the names of files found in a directory. Suppose that L is the result of this command, and that every file in the directory contains a single column of

numbers, and that every file has the same number of rows. Write a program that reads each file and combines them into a single numpy array of floats. Keep in mind that:

if fn is a file name, open(fn) opens the file; if f is an open file, f.read().split() will read the entire file and split it on whitespace, returning a

list of characters: numpy.array has a dtype argument that will convert its argument to the specified type

For example, if there were three files in the directory: a.txt, b.txt, and other_file.txt,

a.txt b.txt other_file.txt

------ ------- --------------

1 17 4

2 18 5

3 150 6

then the result would be

[[ 1. 17. 4.]

[ 2. 18. 5.]

[ 3. 150. 6.]]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!