[Numpy-discussion] Re: numarray: RandomArray2
Jochen Küpper
jochen at jochen-kuepper.de
Sun Aug 18 14:30:02 CDT 2002
On Sun, 18 Aug 2002 08:13:18 -0400 Todd Miller wrote:
Todd> Jochen Küpper wrote:
>> Looking at RandomArray2 I realized that the functions don't do any
>> argument checking. Shouldn't uniform for example check at least
>> whether ,----
>> | minimum != maximum
>> `----
>> or even make sure that maximum > minimum? (Although the result is
>> probably "ok" if it isn't.) Something like
>> ,----
>> | def uniform(minimum, maximum, shape=[]):
>> | """Return array of random Floats in interval ]minimum, maximum[
>> | with shape |shape|.
>> | """
>> | if maximum <= minimum:
>> | raise ValueError
>> | return minimum + (maximum-minimum)*random(shape)
>> `----
>>
Todd> I am +0 on this. The parameter order emulates "range".
Not exactly, currently:
,----
| >>> range(2, -4)
| []
| >>> ran.uniform(2, -4)
| -2.2346744537353516
`----
That is, if max < min range returns an empty list, whereas uniform
comes up with the same result as for (-4, 2) (well, "mirrored").
Also note the "strange" docstring of range:
,----
| range(...)
| range([start,] stop[, step]) -> list of integers
`----
pointing straight toward its behavior.
Todd> While it does look like it will compute the wrong answer if
Todd> called incorrectly, that seems unlikely to me.
Well, if max<min it "mirrors" the result inside the range. This is no
problem as long as it is done "consistently". I don't have enough
knowledge of RNG's to understand whether it is a problem (with respect
to randomness) when calls with the right and wrong ordering of min and
max are mixed.
Thinking about the case min==max I must say it's a very wasted
function call, but no actually big deal:
,----
| >>> import RandomArray2 as ran
| >>> ran.uniform(1, 1)
| 1.0
`----
So well, maybe someone with insight into RNG's can comment on the,
mirroring issue?
>> Moreover there are some inconsistencies between functions, i.e.:
>> ,----
>> | def randint(minimum, maximum=None, shape=[]):
>> `----
>> ,----
>> | def random_integers(maximum, minimum=1, shape=[]):
>> `----
Todd> It appears to me that the parameter order of randint again
Todd> emulates "range". The fact that random_integers is not
Todd> consistent with randint seem OK to me because random_integers
Todd> appears to have been written expressly to tailor the calling
Todd> sequence of randint.
Hmm,
v.s.
Yes, initially I wondered why there are two functions at all. This
explanation sounds like "we wanted some help in confusing the
users" :))
Todd> Because randint re-defines its parameters depending on whether 1
Todd> or 2 range values are used, as does range, I don't think there
Todd> is a completely consistent way to do this. Either we're "wrong"
Todd> for the 1 parameter case or the 2 parameter case. The way it is
Todd> specified now seems simplest to me, with "minimum" preceding
Todd> "maximum", even though it is not strictly the correct name for
Todd> the 1 parameter case.
What's about
,----
| uniform(limit1, limit2, shape=[])
`----
and then range-like behaviour?
But then, what do we return on
,----
| uniform(2, -4)
`----
???
To make it compatible with range, it should be an empty list, no?
Your-even-more-confused-ly's,
Jochen
--
Einigkeit und Recht und Freiheit http://www.Jochen-Kuepper.de
Liberté, Égalité, Fraternité GnuPG key: 44BCCD8E
Sex, drugs and rock-n-roll
More information about the Numpy-discussion
mailing list