[Numpy-discussion] Errors with "**" for numpy.float16
#! /usr/bin/env python3.2 import numpy for t in (numpy.float16, numpy.float32, numpy.float64, numpy.float128): two = t(2) print(t, two, two ** two, numpy.power(two, two)) """ I use up-to-date debian testing (wheezy), amd64 architecture. The python package is python3, version 3.2.3~rc1-2. The numpy package is python3-numpy, version 1:1.6.2~rc1-1. "**" has problems for float16: 2.0 1.1921e-07 4.0 2.0 4.0 4.0 2.0 4.0 4.0 2.0 4.0 4.0 """ ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Incorrect overflow warning message for float128
I use up-to-date Debian testing (wheezy), amd64 architecture. From the docs for numpy.MachAr: maxexp int Smallest (positive) power of ibeta that causes overflow. On my machine, ibeta = 2 and maxexp = 16384. For float64, float32, and float16 things behave as expected. For float128, I get the message about overflow for exponent 8192 (and greater) but the correct answer is printed. What is the problem? #! /usr/bin/env python3.2 import numpy print('float128') fi = numpy.finfo(numpy.float128) print('ibeta:', fi.machar.ibeta) # 2 print('maxexp:', fi.machar.maxexp) # 16384 print('xmax:', fi.machar.xmax) # 1.18973149536e+4932 two = numpy.float128(2) big = numpy.float128(8191) x = numpy.power(two, big) print('2**8191:', x) # 5.4537406781e+2465 big = numpy.float128(8192) # RuntimeWarning: overflow encountered in power x = numpy.power(two, big) print('2**8192:', x) # 1.09074813562e+2466 ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
Re: [Numpy-discussion] Are "min", "max" documented for scalars?
Silly mistakes. If a and b are Python ints, Python floats, or non-complex numpy.number's, "max" returns, unchanged, the largrt of the two objects. There is no coercion to a common type. This useful behavior needs to be documented. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Are "min", "max" documented for scalars?
Python "max" and "min" have an interesting and _useful_ behavior when applied to numpy scalars and Python numbers. Here is a piece of pseudo-code: def max(a, b): if int(b) > int(a): return b else: return a The larger object is returned unchanged. If the two objects are equal, return the first unchanged. Is the behavior of "max", "min", "<", "<=", etc. for numpy scalar objects documented somewhere? keywords: greater than less than ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] numpy.clip behavior at max and min of dtypes
Can the following function be written using numpy.clip? In some other way? Does numpy.clip satisfy condition 4 below? Does numpy.clip satisfy some closely related condition? Define a function clipcast: output = clipcast(arr, dtype=None, out=None) 1. All arrays have int or float dtypes. 2. Exactly one of the keyword arguments "dtype" and "out" must be used. If "dtype" is given, then output has that dtype. 3. "output" has the same shape as "arr". 4. Let ER be the set of all the real numbers that can be exactly represented by the output dtype. ER is finite and bounded. Let themin = min(ER) and themax = max(ER). For any real number x, define a function f(x) by If x is in ER, define f(x) = x. If x is between two consecutive numbers, u and v, in ER, then define f(x) = u or f(x) = v. Probably the choice would be made using a C cast. If x < themin, define f(x) = themin. If x > themax, define f(x) = themax. If x is an element of arr, say Arr[I], then output[I] == f(x) where I is any index that defines a single element of arr. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
[Numpy-discussion] Permuting sparse arrays
I have a vector of bits where there are many more zeros than one. I store the array as a sorted list of the indexes where the bit is one. If the bit array is (0, 1, 0, 0, 0, 1, 1), it is stored as (1, 5, 6). If the bit array, b, has length n, and p is a random permutation of arange(n), then I can permute the bit array using fancy indexing: b[p]. Is there some neat trick I can use to permute an array while leaving it in the list-of-indexes form? Currently I am doing it with a Python loop but I am looking for a faster way. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion