I'm trying to write a program which takes 2 inputs from the user.
- The location of a text file containing an array and
- A column in the array.
Then I want to extract that column from the array, and perform functions on it using my own module stats.
I've tried setting a variable i.e.,
def arcol(fname, i):
data = np.loadtxt(fname, usecols=i)
return data
in the function, but it doesn't like the apparent string usecols is set to.
Here's the code I have, the error is that the variables in the print() are not defined.
import numpy as np
import stats as st
def setInput1():
fname = input("Please enter file location/path:")
return fname
def setInput2():
i = input("Please enter the desired column in the array:")
return i
def arcol(fname, i):
return np.loadtxt(fname, usecols= i)
print(st.mean(arcol(fname, i)))
arcolassumes it's an int. Try,i = int(i). Also, you don't show where you call the functions, so without a runable example, it's hard to say what's going on.ior thefnameyou are passing inprint(st.mean(arcol(fname, i))), so obviously you will get an error telling you they aren't definedsetInput1andsetInput1is called somewhere?