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
(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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started