Sinisterly
Issues with numpy or more likely myself. - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Python (https://sinister.ly/Forum-Python)
+--- Thread: Issues with numpy or more likely myself. (/Thread-Issues-with-numpy-or-more-likely-myself)



Issues with numpy or more likely myself. - -ELM - 04-12-2013

*snip*


RE: Issues with numpy or more likely myself. - Ex094 - 04-12-2013

I have not used Numpy but you should see Array section of this website http://www.scipy.org/Tentative_NumPy_Tutorial#head-a476da892560e3bf994ec9b363e169b6467cd5a4


RE: Issues with numpy or more likely myself. - Deque - 04-12-2013

Please explain or make a small example: What is the content of the txt file and what output do you expect?


RE: Issues with numpy or more likely myself. - -ELM - 04-12-2013

(04-12-2013, 07:07 PM)Deque Wrote: Please explain or make a small example: What is the content of the txt file and what output do you expect?

Apologies for my lack of clarity. The file being imported is simply two columns of one hundred lines of data. I'm trying to manipulate the data such that I can work out statistical properties such as the mean by:
Code:
mean = sum(x)/100.0
However the [x] array I am trying to read from is not being registered and consequently python is giving me a default array of numbers from one to hundred.

More specifically the plotted data follows a trend of which I am familiar with and know the general equation of. My intent is to try and fit this general curve to the data set and compare with other curve fittings using inbuilt routines from other Python modules.


RE: Issues with numpy or more likely myself. - Deque - 04-12-2013

(04-12-2013, 07:24 PM)-ELM Wrote:
(04-12-2013, 07:07 PM)Deque Wrote: Please explain or make a small example: What is the content of the txt file and what output do you expect?

Apologies for my lack of clarity. The file being imported is simply two columns of one hundred lines of data. I'm trying to manipulate the data such that I can work out statistical properties such as the mean by:
Code:
mean = sum(x)/100.0
However the [x] array I am trying to read from is not being registered and consequently python is giving me a default array of numbers from one to hundred.

More specifically the plotted data follows a trend of which I am familiar with and know the general equation of. My intent is to try and fit this general curve to the data set and compare with other curve fittings using inbuilt routines from other Python modules.

I well understood what you want to do. But I need an example of how your file looks like.
You say you get an array with numbers from 1 to 100 in it. There is a reason for this and to find the reason properly I need a little and concrete example of the contents of your txt file (I guess a few lines would be sufficient).

I see that there is similar example here: http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html

Code:
>>> c = StringIO("1,0,2\n3,0,4") >>> x, y = np.loadtxt(c, delimiter=',', usecols=(0, 2), unpack=True) >>> x array([ 1., 3.]) >>> y array([ 2., 4.])

But here they specified a delimiter and which columns to put in x and y. You didn't specify that, so I am asking myself what kind of data you expect to be in x, if there are not several columns you can unpack.

The only thing that gives me more clarity is your .txt file.


RE: Issues with numpy or more likely myself. - -ELM - 04-12-2013

(04-12-2013, 07:49 PM)Deque Wrote:
(04-12-2013, 07:24 PM)-ELM Wrote:
(04-12-2013, 07:07 PM)Deque Wrote: Please explain or make a small example: What is the content of the txt file and what output do you expect?

Apologies for my lack of clarity. The file being imported is simply two columns of one hundred lines of data. I'm trying to manipulate the data such that I can work out statistical properties such as the mean by:
Code:
mean = sum(x)/100.0
However the [x] array I am trying to read from is not being registered and consequently python is giving me a default array of numbers from one to hundred.

More specifically the plotted data follows a trend of which I am familiar with and know the general equation of. My intent is to try and fit this general curve to the data set and compare with other curve fittings using inbuilt routines from other Python modules.

I well understood what you want to do. But I need an example of how your file looks like.
You say you get an array with numbers from 1 to 100 in it. There is a reason for this and to find the reason properly I need a little and concrete example of the contents of your txt file (I guess a few lines would be sufficient).

I see that there is similar example here: http://docs.scipy.org/doc/numpy/reference/generated/numpy.loadtxt.html

Code:
>>> c = StringIO("1,0,2\n3,0,4") >>> x, y = np.loadtxt(c, delimiter=',', usecols=(0, 2), unpack=True) >>> x array([ 1., 3.]) >>> y array([ 2., 4.])

But here they specified a delimiter and which columns to put in x and y. You didn't specify that, so I am asking myself what kind of data you expect to be in x, if there are not several columns you can unpack.

The only thing that gives me more clarity is your .txt file.

Yeah I was using usecols=[0,1] previously but as there are only two columns of data and two arrays are being defined from these columns so I simply omitted it for self clarity. Having saved the data file under a different name and retyped the code countless times it has now decided to work. I have no idea what was going wrong previously but apologies for wasting your time! A huge thanks for your efforts in assisting me nonetheless.

EDIT: Shall I delete the thread or leave for a moderator to mark it as solved?


RE: Issues with numpy or more likely myself. - Deque - 04-12-2013

-marked as solved-