Closed moorepants closed 13 years ago
Hello Jason,
If I understand what you need to do, it does already exist:
from numpy import array from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = array([a, b]) # You do not have to set dtype!
Is this what you wanted?
EOL
On Tue, 3 May 2011, moorepants wrote:
I often have several ufloat variables that I'd like to insert into a numpy array and then manipulate them with the unumpy functionality. For example
from numpy import array from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = array([a, b], dtype=object)
It would be nice not to have to type ", dtype=object" everytime. The equivalent functionality with floats and numpy arrays is that you don't have to declare the dtype. Alternatively, making the array c with unumpy.uarray is clumsy because you have to declare the nominal values and uncertainties separetly. It would be nice to be able to type this:
from uncertainties import unumpy from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = unumpy.uarray([a, b])
PS: What I am referring to is described at http://packages.python.org/uncertainties/numpy_guide.html#creation-and-manipulation-of-arrays-and-matrices
Do you think I should make it more explicit?
On Wed, 4 May 2011, Eric O. LEBIGOT (EOL) wrote:
Hello Jason,
If I understand what you need to do, it does already exist:
from numpy import array from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = array([a, b]) # You do not have to set dtype!
Is this what you wanted?
EOL
On Tue, 3 May 2011, moorepants wrote:
I often have several ufloat variables that I'd like to insert into a numpy array and then manipulate them with the unumpy functionality. For example
from numpy import array from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = array([a, b], dtype=object)
It would be nice not to have to type ", dtype=object" everytime. The equivalent functionality with floats and numpy arrays is that you don't have to declare the dtype. Alternatively, making the array c with unumpy.uarray is clumsy because you have to declare the nominal values and uncertainties separetly. It would be nice to be able to type this:
from uncertainties import unumpy from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = unumpy.uarray([a, b])
I've been getting errors in my code which went away when I added the "dtype=object". Let me try to recreate what is actually happening and I'll send you a better code snippet (or I'll figure out what I'm doing wrong!).
Jason
On Wed, May 4, 2011 at 1:51 AM, lebigot < reply@reply.github.com>wrote:
PS: What I am referring to is described at
Do you think I should make it more explicit?
On Wed, 4 May 2011, Eric O. LEBIGOT (EOL) wrote:
Hello Jason,
If I understand what you need to do, it does already exist:
from numpy import array from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = array([a, b]) # You do not have to set dtype!
Is this what you wanted?
EOL
On Tue, 3 May 2011, moorepants wrote:
I often have several ufloat variables that I'd like to insert into a numpy array and then manipulate them with the unumpy functionality. For example
from numpy import array from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = array([a, b], dtype=object)
It would be nice not to have to type ", dtype=object" everytime. The equivalent functionality with floats and numpy arrays is that you don't have to declare the dtype. Alternatively, making the array c with unumpy.uarray is clumsy because you have to declare the nominal values and uncertainties separetly. It would be nice to be able to type this:
from uncertainties import unumpy from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = unumpy.uarray([a, b])
Reply to this email directly or view it on GitHub: https://github.com/lebigot/uncertainties/issues/4#comment_1098720
http://mae.ucdavis.edu/~biosport/jkm/ Sports Biomechanics Lab http://biosport.ucdavis.edu, UC Davis Davis Bike Collective http://www.davisbikecollective.org Minister, Davis, CA BikeDavis.info Office: +01 530-752-2163 Lab: +01 530-752-2235 Home: +01 530-753-0794
Ok, I figured it out, my mistake. This is where my errors are coming from. I often create an array and then want to fill it with ufloats and that doesn't work unless the dtype is correct. Here is an example:
from numpy import array, zeros
from uncertainties import ufloat
a = ufloat((1., .1))
b = ufloat((2., .1))
c = zeros(2) # this should be c = zeros(2, dtype=object) for it to work
c[0] = a
c[1] = b
Alright. Thanks for the details. Assigning a complex numbers produces a similar error:
c[0] = 1+2j
Traceback (most recent call last): File "
", line 1, in TypeError: can't convert complex to float
So, I think that the current situation is indeed normal. :)
Thank you for the feedback! Next time, the problem could on my side. :)
EOL
On Wed, 4 May 2011, moorepants wrote:
Ok, I figured it out, my mistake. This is where my errors are coming from. I often create an array and then want to fill it with ufloats and that doesn't work unless the dtype is correct. Here is an example:
from numpy import array, zeros from uncertainties import ufloat a = ufloat((1., .1)) b = ufloat((2., .1)) c = zeros(2) # this should be c = zeros(2, dtype=object) for it to work c[0] = a c[1] = b
I agree, it is the normal functionality. Thanks for looking into it.
I often have several ufloat variables that I'd like to insert into a numpy array and then manipulate them with the unumpy functionality. For example
It would be nice not to have to type ", dtype=object" everytime. The equivalent functionality with floats and numpy arrays is that you don't have to declare the dtype for floats. Alternatively, making the array c with unumpy.uarray is clumsy because you have to declare the nominal values and uncertainties separetly. It would be nice to be able to type this: