Determining rows and columns in data txt file?


So the question is:

The rows in the data to be loaded represent various time points of measurement (called "frames" henceforth), the columns various measurements provided by the experimental apparatus at those time points.
The data is in the tab-delimited text file called "exampleData.txt" and can be imported using NumPy’s loadtxt.
Determine the number of rows and columns of the data array and save them as variables for later.
Print out the number of rows and columns in the data array.

I have done:

data = np.loadtxt("./exampleData.txt", delimiter = "t")

Correct me if I am wrong.

But I have trouble trying to do the next steps – the determining of the rows and columns and then printing out.

Asked By: arikah.



data.shape will return the the rows and columns as a tuple. You can use tuple assignment to put the value in variables:

import numpy as np

data = np.loadtxt("./exampleData.txt", delimiter = "t")
rows, columns = data.shape
Answered By: Mark Tolonen