python - Using numpy's function loadtxt() to read a two column file then using polyfit() to return an array -


afile given file, , z degree of polynomial. been breaking head on while, frustrating how i'm given 0 instructions on how proceed.

this thought should like:

import numpy np def newfile(afile,z):     x,y = np.loadtxt(afile)     d= np.polyfit(x,y,z)     return d 

i have attempted as

data = np.loadtxt(afile) x = data[0:] 

by printing "data" i'm given format:

[[   2.      888.8425]  [   6.      888.975 ]  [  14.      888.1026]  [  17.      888.2071]  [  23.      886.0479]  [  26.      883.3316]  [  48.      877.04  ]  [ 99.       854.3665]] 

by printing "x" in case gives me whole list (i'm thinking issue lies in lack of comma). in case i'd want x array of left column.

i suppose getting error when unpacking in statement:

x,y = np.loadtxt(afile) 

you should replace this:

x, y = zip(*np.loadtxt(afile)) 

the rest should work


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -