Yosef Meller | 1 Jul 07:09
Picon
Picon
Gravatar

Re: single elements and arrays

On Monday 30 June 2008 21:57:18 Robert Kern wrote:
> On Mon, Jun 30, 2008 at 13:14, Gideon Simpson <grs2103 <at> columbia.edu> wrote:
> > foo finds a root where x is a parameter in the equation to be solved.
> > If x is an array, I iterate through the elements of the array.
>
> In that case, just special case it. Use numpy.isscalar() to do the test.

Or else, put this at the beginning:
x = numpy.atleast_1d(x)
Robert Kern | 1 Jul 07:13
Picon
Gravatar

Re: single elements and arrays

On Tue, Jul 1, 2008 at 00:09, Yosef Meller <yosefmel <at> post.tau.ac.il> wrote:
> On Monday 30 June 2008 21:57:18 Robert Kern wrote:
>> On Mon, Jun 30, 2008 at 13:14, Gideon Simpson <grs2103 <at> columbia.edu> wrote:
>> > foo finds a root where x is a parameter in the equation to be solved.
>> > If x is an array, I iterate through the elements of the array.
>>
>> In that case, just special case it. Use numpy.isscalar() to do the test.
>
> Or else, put this at the beginning:
> x = numpy.atleast_1d(x)

Presumably, he also wants to return a scalar if given a scalar. The
general outline would probably look like this:

def foo(x):
    xisscalar = numpy.isscalar(x)
    x = numpy.atleast_1d(x)
    y = ...
    if xisscalar:
        y = y[0]
    return y

--

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco
(Continue reading)

Anne Archibald | 1 Jul 07:49
Picon

Re: single elements and arrays

2008/6/30 Gideon Simpson <grs2103 <at> columbia.edu>:
> foo finds a root where x is a parameter in the equation to be solved.
> If x is an array, I iterate through the elements of the array.

If you're actually *iterating*, in the sense of using a python loop to
go through every element, there will be substantial overhead -
something like a few tens or hundreds of floating-point operations for
every trip through the loop -  involved in looping. If the function
itself is reasonably fast and if you can write it in terms of vectors,
that will be much faster. It may also, with some care, operate
transparently on scalars.

However, if you can't - let's say it's a numerical root-finding using
brentq - then there's a handy tool to provide python-level looping:
the vectorize decorator:

@np.vectorize
def acos(y):
    return scipy.optimize.brentq(lambda x: y-np.cos(x),0,np.pi)

This makes acos behave a little like a ufunc from the user's point of
view: you can hand it a scalar or an array of arbitrary dimensionality
and it will iterate as appropriate. The iteration passes through
python, necessarily since the function being wrapped is in python, so
it won't be fast, but it is convenient.

Anne
Picon

Is there a way to use Sundials with scipy?

I am a new user of both python and scipy and was searching for a way to use sundials with scipy.
I found some old messages in the history of the mailing list dating back to 2004, but nothing indicating wether such a wrapper was effectively developed.
At the present, is it possible to use saundials with scipy?

Thanks,

Marcus Vinicius Eiffle Duarte

_______________________________________________
SciPy-user mailing list
SciPy-user <at> scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user
Robert Cimrman | 1 Jul 16:13
Picon

ANN: SfePy 00.46.02


I am pleased announce the release of SfePy 00.46.02.

SfePy is a finite element analysis software in Python, based primarily
on Numpy and SciPy.

Mailing lists, issue tracking, mercurial repository: http://sfepy.org
Home page: http://sfepy.kme.zcu.cz

Major improvements:
- alternative short syntax for specifying essential boundary conditions, 
variables and regions
- manufactured solutions tests:
     - SymPy support
- site configuration now via script/config.py + site_cfg.py
- new solvers
- new terms

For more information on this release, see
http://sfepy.googlecode.com/svn/web/releases/004602_RELEASE_NOTES.txt

If you happen to come to Leipzig for EuroSciPy 2008, see you there!

Best regards,
Robert Cimrman & SfePy developers

Nils Wagner | 1 Jul 19:04
Picon
Favicon

Re: Is there a way to use Sundials with scipy?

On Tue, 1 Jul 2008 10:30:07 -0300
  "Marcus Vinicius Eiffle Duarte" <eiffleduarte <at> gmail.com> 
wrote:
> I am a new user of both python and scipy and was 
>searching for a way to use
> sundials with scipy.
> I found some old messages in the history of the mailing 
>list dating back to
> 2004, but nothing indicating wether such a wrapper was 
>effectively
> developed.
> At the present, is it possible to use saundials with 
>scipy?
> 
> Thanks,
> 
> Marcus Vinicius Eiffle Duarte

Hi Marcus,

you can use

svn co 
https://pysundials.svn.sourceforge.net/svnroot/pysundials/ 
pysundials

to get the latest version of pysundials.
Sundials is required of course.

* Download and untar the complete SUNDIALS suite.
* $ ./configure --enable-shared
* $ make && make install

* $ python setup.py install

Further information is given in pysundials/doc/README

Cheers,

          Nils
Travis Vaught | 2 Jul 16:32

Enthought Python Distribution

Greetings,

We're pleased to announce the beta release of the Enthought Python  
Distribution for *Mac OS X*.

http://www.enthought.com/products/epd.php

This release should safely install alongside other existing Python  
installations on your Mac.  With the Mac OS X platform support, EPD  
now provides a consistent scientific application tool set across three  
major platforms (Windows, RedHat Linux (32 and 64 bit) and OS X). This  
is a _beta_ release, so install at your own risk.  Please provide any  
feedback to info <at> enthought.com.  See the included EPD Readme.txt for  
instructions and known issues.

About EPD
---------
The Enthought Python Distribution (EPD) is a "kitchen-sink-included"  
distribution of the Pythonâ„¢ Programming Language, including over 60  
additional tools and libraries. The EPD bundle includes the following  
major packages:

Python       Core Python
NumPy        Multidimensional arrays and fast numerics for Python
SciPy        Scientific Library for Python
Enthought Tool Suite (ETS)   A suite of tools including:
   Traits     Manifest typing, validation, visualization, delegation,  
etc.
   Mayavi     3D interactive data exploration environment.
   Chaco      Advanced 2D plotting toolkit for interactive 2D  
visualization.
   Kiva       2D drawing library in the spirit of DisplayPDF.
   Enable     Object-based canvas for interacting with 2D components  
and widgets.
Matplotlib   2D plotting library
wxPython     Cross-platform windowing and widget library.
Visualization Toolkit (VTK)  3D visualization framework

There are many more included packages as well.  There's a complete  
list here:

http://www.enthought.com/products/epdlibraries.php

License
-------
EPD is a bundle of software--every piece of which is available for  
free under various open-source licenses.  The bundle itself is offered  
as a free download to academic and individual hobbyist use.   
Commercial and non-degree granting institutions and agencies may  
purchase individual subscriptions for the bundle
(http://www.enthought.com/products/order.php?ver=MacOSX 
) or contact Enthought to discuss an Enterprise license
(http://www.enthought.com/products/enterprise.php 
).  Please see the FAQ for further explanation about how the software  
came together. (http://www.enthought.com/products/epdfaq.php)

Thanks,

Travis
Fernando Perez | 2 Jul 19:10
Picon
Gravatar

Re: Enthought Python Distribution

Hey Travis,

On Wed, Jul 2, 2008 at 7:32 AM, Travis Vaught <travis <at> enthought.com> wrote:
> Greetings,
>
> We're pleased to announce the beta release of the Enthought Python
> Distribution for *Mac OS X*.

First of all, this is *fantastic*.  OSX has been a major pain for us
here in terms of distribution, so I am extremely happy and grateful to
you guys for putting this out.

Two minor requests: any chance in the next release, you could update
ipython and matplotlib?  You are shipping 0.8.1 and 0.91.2, both of
which are fairly old and the current versions of both do have
reasonably useful improvements and fixes (ipython has threading fixes
that impact plotting, and mpl has all the new mathtext code that gives
good math rendering without needing latex).

In any case, a big cheer from me :)

Regards,

f
Gideon Simpson | 3 Jul 05:19
Favicon

0.7 test results

On an OS X 10.5.4 machine with fink python 2.5.2 and numpy 1.1.0, I  
get the following output when running scipy.test() with scipy  
0.7.0.dev4518:

/opt/lib/python2.5/site-packages/scipy/sparse/linalg/dsolve/ 
linsolve.py:20: DeprecationWarning: scipy.sparse.linalg.dsolve.umfpack  
will be removed, install scikits.umfpack instead
   ' install scikits.umfpack instead', DeprecationWarning )
/opt/lib/python2.5/site-packages/scipy/linsolve/__init__.py:4:  
DeprecationWarning: scipy.linsolve has moved to  
scipy.sparse.linalg.dsolve
   warn('scipy.linsolve has moved to scipy.sparse.linalg.dsolve',  
DeprecationWarning)
/opt/lib/python2.5/site-packages/scipy/splinalg/__init__.py:3:  
DeprecationWarning: scipy.splinalg has moved to scipy.sparse.linalg
   warn('scipy.splinalg has moved to scipy.sparse.linalg',  
DeprecationWarning)
....(1, 1) (0,)
(2, 2) (1,)
(3, 3) (3,)
(4, 4) (6,)
(5, 5) (10,)
(6, 6) (15,)
(7, 7) (21,)
(8, 8) (28,)
(9, 9) (36,)
................/opt/lib/python2.5/site-packages/scipy/cluster/vq.py: 
570: UserWarning: One of the clusters is empty. Re-run kmean with a  
different initialization.
   warnings.warn("One of the clusters is empty. "
exception raised as expected: One of the clusters is empty. Re-run  
kmean with a different initialization.
................................................................./opt/ 
lib/python2.5/site-packages/scipy/interpolate/fitpack2.py:479:  
UserWarning:
The coefficients of the spline returned have been computed as the
minimal norm least-squares solution of a (numerically) rank deficient
system (deficiency=7). If deficiency is large, the results may be
inaccurate. Deficiency may strongly depend on the value of eps.
   warnings.warn(message)
..../opt/lib/python2.5/site-packages/scipy/interpolate/fitpack2.py: 
420: UserWarning:
The required storage space exceeds the available storage space: nxest
or nyest too small, or s too small.
The weighted least-squares spline corresponds to the current set of
knots.
   warnings.warn(message)
.....................................................................................
Don't worry about a warning regarding the number of bytes read.
Warning: 1000000 bytes requested, 20 bytes read.
./opt/lib/python2.5/site-packages/numpy/lib/utils.py:114:  
DeprecationWarning: write_array is deprecated
   warnings.warn(str1, DeprecationWarning)
/opt/lib/python2.5/site-packages/numpy/lib/utils.py:114:  
DeprecationWarning: read_array is deprecated
   warnings.warn(str1, DeprecationWarning)
....................../opt/lib/python2.5/site-packages/numpy/lib/ 
utils.py:114: DeprecationWarning: npfile is deprecated
   warnings.warn(str1, DeprecationWarning)
............................caxpy:n=4
..caxpy:n=3
....ccopy:n=4
..ccopy:n=3
.............cscal:n=4
....cswap:n=4
..cswap:n=3
.....daxpy:n=4
..daxpy:n=3
....dcopy:n=4
..dcopy:n=3
.............dscal:n=4
....dswap:n=4
..dswap:n=3
.....saxpy:n=4
..saxpy:n=3
....scopy:n=4
..scopy:n=3
.............sscal:n=4
....sswap:n=4
..sswap:n=3
.....zaxpy:n=4
..zaxpy:n=3
....zcopy:n=4
..zcopy:n=3
.............zscal:n=4
....zswap:n=4
..zswap:n=3
..
****************************************************************
WARNING: clapack module is empty
-----------
See scipy/INSTALL.txt for troubleshooting.
Notes:
* If atlas library is not found by numpy/distutils/system_info.py,
   then scipy uses flapack instead of clapack.
****************************************************************

..........................................NO ATLAS INFO AVAILABLE
.........................................
****************************************************************
WARNING: cblas module is empty
-----------
See scipy/INSTALL.txt for troubleshooting.
Notes:
* If atlas library is not found by numpy/distutils/system_info.py,
   then scipy uses fblas instead of
cblas.
****************************************************************

...............................................................................................caxpy:n 
=4
..caxpy:n=3
....ccopy:n=4
..ccopy:n=3
.............cscal:n=4
....cswap:n=4
..cswap:n=3
.....daxpy:n=4
..daxpy:n=3
....dcopy:n=4
..dcopy:n=3
.............dscal:n=4
....dswap:n=4
..dswap:n=3
.....saxpy:n=4
..saxpy:n=3
....scopy:n=4
..scopy:n=3
.............sscal:n=4
....sswap:n=4
..sswap:n=3
.....zaxpy:n=4
..zaxpy:n=3
....zcopy:n=4
..zcopy:n=3
.............zscal:n=4
....zswap:n=4
..zswap:n=3
....
****************************************************************
WARNING: clapack module is empty
-----------
See scipy/INSTALL.txt for troubleshooting.
Notes:
* If atlas library is not found by numpy/distutils/system_info.py,
   then scipy uses flapack instead of clapack.
****************************************************************

...Result may be inaccurate, approximate err = 1.23518201169e-08
...Result may be inaccurate, approximate err = 7.27595761418e-12
.....SSS

........................................................................................................................................................................................................................................................................................................................................................................................................./opt 
/lib/python2.5/site-packages/scipy/ndimage/_registration.py:25:  
UserWarning: The registration code is under heavy development and  
therefore the public API will change in the future.  The NIPY group is  
actively working on this code, and has every intention of generalizing  
this for the Scipy community.  Use this module minimally, if at all,  
until it this warning is removed.
   warnings.warn(_msg, UserWarning)
...E..EEE./opt/lib/python2.5/site-packages/scipy/ndimage/_segmenter.py: 
30: UserWarning: The segmentation code is under heavy development and  
therefore the public API will change in the future.  The NIPY group is  
actively working on this code, and has every intention of generalizing  
this for the Scipy community.  Use this module minimally, if at all,  
until it this warning is removed.
   warnings.warn(_msg, UserWarning)
...F 
................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
 F 
......................EE 
......................................................................................Ties 
  preclude use of exact statistic.
..Ties preclude use of exact statistic.
........................................................../opt/lib/ 
python2.5/site-packages/numpy/lib/function_base.py:166: FutureWarning:
         The semantics of histogram will be modified in
         release 1.2 to improve outlier handling. The new behavior can  
be
         obtained using new=True. Note that the new version accepts/ 
returns
         the bin edges instead of the left bin edges.
         Please read the docstring for more information.
   Please read the docstring for more information.""", FutureWarning)
/opt/lib/python2.5/site-packages/numpy/lib/function_base.py:181:  
FutureWarning:
                 Outliers handling will change in version 1.2.
                 Please read the docstring for details.
   Please read the docstring for details.""",
FutureWarning)
................................................................................................warning 
: specified build_dir '_bad_path_' does not exist or is not writable.  
Trying default locations
...warning: specified build_dir '..' does not exist or is not  
writable. Trying default locations
..warning: specified build_dir '_bad_path_' does not exist or is not  
writable. Trying default locations
...warning: specified build_dir '..' does not exist or is not  
writable. Trying default locations
............................building extensions here: /Users/ 
gideon/.python25_compiled/m11
................................................................................................
======================================================================
ERROR: Execute a single test.  Returns a success boolean
----------------------------------------------------------------------
TypeError: exec_test() takes exactly 4 arguments (1 given)

======================================================================
ERROR: Run one test with arguments
----------------------------------------------------------------------
TypeError: run_test() takes exactly 3 arguments (1 given)

======================================================================
ERROR: Run many tests with a common setUp/tearDown.
----------------------------------------------------------------------
TypeError: run_tests() takes exactly 3 arguments (1 given)

======================================================================
ERROR: set_testMethodDoc (test_regression.ParametricTestCase)
----------------------------------------------------------------------
TypeError: set_testMethodDoc() takes exactly 2 arguments (1 given)

======================================================================
ERROR: test_huber (test_scale.TestScale)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/opt/lib/python2.5/site-packages/scipy/stats/models/tests/ 
test_scale.py", line 35, in test_huber
     m = scale.huber(X)
   File "/opt/lib/python2.5/site-packages/scipy/stats/models/robust/ 
scale.py", line 82, in __call__
     for donothing in self:
   File "/opt/lib/python2.5/site-packages/scipy/stats/models/robust/ 
scale.py", line 102, in next
     scale = N.sum(subset * (a - mu)**2, axis=self.axis) / (self.n *  
Huber.gamma - N.sum(1. - subset, axis=self.axis) * Huber.c**2)
   File "/opt/lib/python2.5/site-packages/numpy/core/fromnumeric.py",  
line 994, in sum
     return sum(axis, dtype, out)
TypeError: only length-1 arrays can be converted to Python scalars

======================================================================
ERROR: test_huberaxes (test_scale.TestScale)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/opt/lib/python2.5/site-packages/scipy/stats/models/tests/ 
test_scale.py", line 40, in test_huberaxes
     m = scale.huber(X, axis=0)
   File "/opt/lib/python2.5/site-packages/scipy/stats/models/robust/ 
scale.py", line 82, in __call__
     for donothing in self:
   File "/opt/lib/python2.5/site-packages/scipy/stats/models/robust/ 
scale.py", line 102, in next
     scale = N.sum(subset * (a - mu)**2, axis=self.axis) / (self.n *  
Huber.gamma - N.sum(1. - subset, axis=self.axis) * Huber.c**2)
   File "/opt/lib/python2.5/site-packages/numpy/core/fromnumeric.py",  
line 994, in sum
     return sum(axis, dtype, out)
TypeError: only length-1 arrays can be converted to Python scalars

======================================================================
FAIL: test_texture2 (test_segment.TestSegment)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/opt/lib/python2.5/site-packages/scipy/ndimage/tests/ 
test_segment.py", line 152, in test_texture2
     assert_array_almost_equal(tem0, truth_tem0, decimal=6)
   File "/opt/lib/python2.5/site-packages/numpy/testing/utils.py",  
line 255, in assert_array_almost_equal
     header='Arrays are not almost equal')
   File "/opt/lib/python2.5/site-packages/numpy/testing/utils.py",  
line 240, in assert_array_compare
     assert cond, msg
AssertionError:
Arrays are not almost equal

(mismatch 66.6666666667%)
  x: array([  0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          1.91816598e-01,   1.02515288e-01,   9.30087343e-02,...
  y: array([ 0.        ,  0.        ,  0.        ,  0.        ,   
0.        ,
         0.        ,  0.13306101,  0.08511007,  0.05084148,  0.07550675,
         0.4334695 ,  0.03715914,  0.00289055,  0.02755581,  0.48142046,
         0.03137803,  0.00671277,  0.51568902,  0.01795249,   
0.49102375,  1.        ], dtype=float32)

======================================================================
FAIL: test_namespace (test_formula.TestFormula)
----------------------------------------------------------------------
Traceback (most recent call last):
   File "/opt/lib/python2.5/site-packages/scipy/stats/models/tests/ 
test_formula.py", line 119, in test_namespace
     self.assertEqual(xx.namespace, Y.namespace)
AssertionError: {} != {'Y': array([ 0,  2,  4,  6,  8, 10, 12, 14, 16,  
18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40,
        42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70,  
72, 74, 76, 78, 80, 82,
        84, 86, 88, 90, 92, 94, 96, 98]), 'X': array([ 0,  1,  2,  3,   
4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
        21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,  
36, 37, 38, 39, 40, 41,
        42, 43, 44, 45, 46, 47, 48, 49])}

----------------------------------------------------------------------
Ran 2275 tests in 23.705s

FAILED (SKIP=3, errors=6, failures=2)
Nils Wagner | 3 Jul 11:24
Picon
Favicon

array manipulation

Hi all,

How can I remove duplicate entries from an array ?

  
>>> Omega
array([ 157.08,  314.16,  471.24,  157.08,  157.08, 
 314.16,  314.16,
         471.24,  471.24])

I am looking for an array

Omega_new = array(([157.08,  314.16,  471.24]))

Nils

Gmane