Serge Rey | 1 Feb 04:50
Picon
Favicon

ANN: PySAL 1.3

On behalf of the PySAL development team, I'm happy to announce the
official release of PySAL 1.3.

PySAL is a library of tools for spatial data analysis and
geocomputation written in Python. PySAL 1.3, the fourth official
release of PySAL, includes a number of new features and enhancements:

    - The spatial regression module (spreg) has added:
        - Two Stage Least Squares
        - Spatial Two Stage Least Squares
        - GM Error (KP 98-99)
        - GM Error Homoskedasticity (Drukker et. al, 2010)
        - GM Error Heteroskedasticity (Arraiz et. al, 2010)
        - Spatial HAC variance-covariance estimation
        - Anselin-Kelejian test for residual spatial autocorrelation
of residuals from
        IV regression
        - New utility functions and other helper classes
    - A new contrib module to support user contributed modules. The first
      contrib modules are:
        - Weights Viewer – A Graphical tool for examining spatial weights
        - World To View Transform – A class for modeling viewing
windows, used by Weights Viewer
        - Shapely Extension – Exposes shapely methods as standalone functions
        - Shared Perimeter Weights – calculate shared perimeters weights

along with many bug fixes and smaller enhancements.

PySAL modules
-------------
(Continue reading)

Mads M. Hansen | 1 Feb 12:56
Picon

NumPy and SciPy test failures

I have built NumPy 1.6.1 and SciPy 0.10.0 for Python 3.2 on a Fedora
16 system and I used gfortran, but when I run the tests I get the
following failures and errors

NumPy:

======================================================================
FAIL: test_kind.TestKind.test_all
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
    self.test(*self.arg)
  File "/usr/lib64/python3.2/site-packages/numpy/f2py/tests/test_kind.py",
line 30, in test_all
    'selectedrealkind(%s): expected %r but got %r' %  (i,
selected_real_kind(i), selectedrealkind(i)))
  File "/usr/lib64/python3.2/site-packages/numpy/testing/utils.py",
line 34, in assert_
    raise AssertionError(msg)
AssertionError: selectedrealkind(19): expected -1 but got 16

======================================================================
FAIL: test_doctests (test_polynomial.TestDocs)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib64/python3.2/site-packages/numpy/lib/tests/test_polynomial.py",
line 84, in test_doctests
    return rundocs()
  File "/usr/lib64/python3.2/site-packages/numpy/testing/utils.py",
line 988, in rundocs
(Continue reading)

Frédéric Bastien | 1 Feb 13:44
Favicon

Re: Accumulation sum using indirect indexes

It will be slow, but you can make a python loop.

Fred

On Jan 31, 2012 3:34 PM, "Alexander Kalinin" <alec.kalinin <at> gmail.com> wrote:
Hello!

I use SciPy in computer graphics applications. My task is to calculate vertex normals by averaging faces normals. In other words I want to accumulate vectors with the same ids. For example,

ids = numpy.array([0, 1, 1, 2])
n = numpy.array([ [0.1, 0.1, 0.1], [0.1, 0.1, 0.1], [0.1, 0.1, 0.1], [0.1, 0.1 0.1] ])

I need result:
nv = ([ [0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.1, 0.1, 0.1]])

The most simple code:
nv[ids] += n
does not work, I know about this. For 1D arrays I use numpy.bincount(...) function. But this function does not work for 2D arrays.

So, my question. What is the best way calculate accumulation sum for 2D arrays using indirect indexes?

Sincerely,
Alexander

_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
Charles R Harris | 1 Feb 15:01
Picon

Re: NumPy and SciPy test failures



On Wed, Feb 1, 2012 at 4:56 AM, Mads M. Hansen <madsmh <at> gmail.com> wrote:
I have built NumPy 1.6.1 and SciPy 0.10.0 for Python 3.2 on a Fedora
16 system and I used gfortran, but when I run the tests I get the
following failures and errors

NumPy:

======================================================================
FAIL: test_kind.TestKind.test_all
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
   self.test(*self.arg)
 File "/usr/lib64/python3.2/site-packages/numpy/f2py/tests/test_kind.py",
line 30, in test_all
   'selectedrealkind(%s): expected %r but got %r' %  (i,
selected_real_kind(i), selectedrealkind(i)))
 File "/usr/lib64/python3.2/site-packages/numpy/testing/utils.py",
line 34, in assert_
   raise AssertionError(msg)
AssertionError: selectedrealkind(19): expected -1 but got 16


I think this is a bug in the test that comes from adding the float16 type.
 
======================================================================
FAIL: test_doctests (test_polynomial.TestDocs)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib64/python3.2/site-packages/numpy/lib/tests/test_polynomial.py",
line 84, in test_doctests
   return rundocs()
 File "/usr/lib64/python3.2/site-packages/numpy/testing/utils.py",
line 988, in rundocs
   raise AssertionError("Some doctests failed:\n%s" % "\n".join(msg))
AssertionError: Some doctests failed:
**********************************************************************
File "/usr/lib64/python3.2/site-packages/numpy/lib/tests/test_polynomial.py",
line 32, in test_polynomial
Failed example:
   p / q
Expected:
   (poly1d([ 0.33333333]), poly1d([ 1.33333333,  2.66666667]))
Got:
   (poly1d([ 0.333]), poly1d([ 1.333,  2.667]))

**********************************************************************
File "/usr/lib64/python3.2/site-packages/numpy/lib/tests/test_polynomial.py",
line 54, in test_polynomial
Failed example:
   p.integ()
Expected:
   poly1d([ 0.33333333,  1.        ,  3.        ,  0.        ])
Got:
   poly1d([ 0.333,  1.   ,  3.   ,  0.   ])

**********************************************************************
File "/usr/lib64/python3.2/site-packages/numpy/lib/tests/test_polynomial.py",
line 56, in test_polynomial
Failed example:
   p.integ(1)
Expected:
   poly1d([ 0.33333333,  1.        ,  3.        ,  0.        ])
Got:
   poly1d([ 0.333,  1.   ,  3.   ,  0.   ])

**********************************************************************
File "/usr/lib64/python3.2/site-packages/numpy/lib/tests/test_polynomial.py",
line 58, in test_polynomial
Failed example:
   p.integ(5)
Expected:
   poly1d([ 0.00039683,  0.00277778,  0.025     ,  0.        ,  0.        ,
           0.        ,  0.        ,  0.        ])
Got:
   poly1d([ 0.   ,  0.003,  0.025,  0.   ,  0.   ,  0.   ,  0.   ,  0.   ])


----------------------------------------------------------------------:

And SciPy:

======================================================================
ERROR: Failure: ImportError (cannot import name _minimize_neldermead)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/failure.py", line 37, in runTest
   raise self.exc_class(self.exc_val).with_traceback(self.tb)
 File "/usr/lib/python3.2/site-packages/nose/loader.py", line 390, in
loadTestsFromName
   addr.filename, addr.module)
 File "/usr/lib/python3.2/site-packages/nose/importer.py", line 39,
in importFromPath
   return self.importFromDir(dir_path, fqname)
 File "/usr/lib/python3.2/site-packages/nose/importer.py", line 86,
in importFromDir
   mod = load_module(part_fqname, fh, filename, desc)
 File "/usr/lib64/python3.2/site-packages/scipy/optimize/tests/test_anneal.py",
line 10, in <module>
   from scipy.optimize import anneal, minimize
 File "/usr/lib64/python3.2/site-packages/scipy/optimize/minimize.py",
line 16, in <module>
   from .optimize import _minimize_neldermead, _minimize_powell, \
ImportError: cannot import name _minimize_neldermead

======================================================================
ERROR: Failure: ImportError (cannot import name cwt)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/failure.py", line 37, in runTest
   raise self.exc_class(self.exc_val).with_traceback(self.tb)
 File "/usr/lib/python3.2/site-packages/nose/loader.py", line 390, in
loadTestsFromName
   addr.filename, addr.module)
 File "/usr/lib/python3.2/site-packages/nose/importer.py", line 39,
in importFromPath
   return self.importFromDir(dir_path, fqname)
 File "/usr/lib/python3.2/site-packages/nose/importer.py", line 86,
in importFromDir
   mod = load_module(part_fqname, fh, filename, desc)
 File "/usr/lib64/python3.2/site-packages/scipy/signal/tests/test_peak_finding.py",
line 7, in <module>
   from scipy.signal._peak_finding import argrelmax, find_peaks_cwt,
_identify_ridge_lines
 File "/usr/lib64/python3.2/site-packages/scipy/signal/_peak_finding.py",
line 7, in <module>
   from scipy.signal.wavelets import cwt, ricker
ImportError: cannot import name cwt

======================================================================
ERROR: test_iv_cephes_vs_amos_mass_test (test_basic.TestBessel)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib64/python3.2/site-packages/scipy/special/tests/test_basic.py",
line 1642, in test_iv_cephes_vs_amos_mass_test
   c1 = special.iv(v, x)
RuntimeWarning: divide by zero encountered in iv

======================================================================
ERROR: test_continuous_extra.test_cont_extra(<scipy.stats.distributions.loggamma_gen
object at 0x6b38f10>, (0.4141193182605212,), 'loggamma loc, scale
test')
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
   self.test(*self.arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/tests/test_continuous_extra.py",
line 78, in check_loc_scale
   m,v = distfn.stats(*arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1632, in stats
   mu = self._munp(1.0,*goodargs)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 4120, in _munp
   return self._mom0_sc(n,*args)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1166, in _mom0_sc
   self.b, args=(m,)+args)[0]
 File "/usr/lib64/python3.2/site-packages/scipy/integrate/quadpack.py",
line 247, in quad
   retval = _quad(func,a,b,args,full_output,epsabs,epsrel,limit,points)
 File "/usr/lib64/python3.2/site-packages/scipy/integrate/quadpack.py",
line 314, in _quad
   return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1163, in _mom_integ0
   return x**m * self.pdf(x,*args)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1263, in pdf
   place(output,cond,self._pdf(*goodargs) / scale)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 4113, in _pdf
   return exp(c*x-exp(x)-gamln(c))
RuntimeWarning: overflow encountered in exp

======================================================================
ERROR: test_continuous_extra.test_cont_extra(<scipy.stats.distributions.lomax_gen
object at 0x74ff610>, (1.8771398388773268,), 'lomax loc, scale test')
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
   self.test(*self.arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/tests/test_continuous_extra.py",
line 78, in check_loc_scale
   m,v = distfn.stats(*arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1618, in stats
   mu, mu2, g1, g2 = self._stats(*args)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 4644, in _stats
   mu, mu2, g1, g2 = pareto.stats(c, loc=-1.0, moments='mvsk')
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1616, in stats
   mu, mu2, g1, g2 = self._stats(*args,**{'moments':moments})
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 4595, in _stats
   vals = 2*(bt+1.0)*sqrt(b-2.0)/((b-3.0)*sqrt(b))
RuntimeWarning: invalid value encountered in sqrt

======================================================================
ERROR: test_discrete_basic.test_discrete_extra(<scipy.stats.distributions.hypergeom_gen
object at 0x6c9f510>, (30, 12, 6), 'hypergeom entropy nan test')
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
   self.test(*self.arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/tests/test_discrete_basic.py",
line 199, in check_entropy
   ent = distfn.entropy(*arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 6315, in entropy
   place(output,cond0,self.vecentropy(*goodargs))
 File "/usr/lib64/python3.2/site-packages/numpy/lib/function_base.py",
line 1863, in __call__
   theout = self.thefunc(*newargs)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 6669, in _entropy
   lvals = where(vals==0.0,0.0,log(vals))
RuntimeWarning: divide by zero encountered in log

======================================================================
ERROR: test_discrete_basic.test_discrete_extra(<scipy.stats.distributions.hypergeom_gen
object at 0x6c9f510>, (21, 3, 12), 'hypergeom entropy nan test')
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
   self.test(*self.arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/tests/test_discrete_basic.py",
line 199, in check_entropy
   ent = distfn.entropy(*arg)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 6315, in entropy
   place(output,cond0,self.vecentropy(*goodargs))
 File "/usr/lib64/python3.2/site-packages/numpy/lib/function_base.py",
line 1863, in __call__
   theout = self.thefunc(*newargs)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 6669, in _entropy
   lvals = where(vals==0.0,0.0,log(vals))
RuntimeWarning: divide by zero encountered in log

======================================================================
ERROR: test_fit (test_distributions.TestFitMethod)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib64/python3.2/site-packages/scipy/stats/tests/test_distributions.py",
line 439, in test_fit
   vals2 = distfunc.fit(res, optimizer='powell')
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1875, in fit
   vals = optimizer(func,x0,args=(ravel(data),),disp=0)
 File "/usr/lib64/python3.2/site-packages/scipy/optimize/optimize.py",
line 1622, in fmin_powell
   fval, x, direc1 = _linesearch_powell(func, x, direc1, tol=xtol*100)
 File "/usr/lib64/python3.2/site-packages/scipy/optimize/optimize.py",
line 1492, in _linesearch_powell
   alpha_min, fret, iter, num = brent(myfunc, full_output=1, tol=tol)
 File "/usr/lib64/python3.2/site-packages/scipy/optimize/optimize.py",
line 1313, in brent
   brent.optimize()
 File "/usr/lib64/python3.2/site-packages/scipy/optimize/optimize.py",
line 1214, in optimize
   tmp2 = (x-v)*(fx-fw)
RuntimeWarning: invalid value encountered in double_scalars

======================================================================
ERROR: test_fix_fit (test_distributions.TestFitMethod)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib64/python3.2/site-packages/scipy/stats/tests/test_distributions.py",
line 460, in test_fix_fit
   vals2 = distfunc.fit(res,fscale=1)
 File "/usr/lib64/python3.2/site-packages/scipy/stats/distributions.py",
line 1875, in fit
   vals = optimizer(func,x0,args=(ravel(data),),disp=0)
 File "/usr/lib64/python3.2/site-packages/scipy/optimize/optimize.py",
line 302, in fmin
   and max(abs(fsim[0]-fsim[1:])) <= ftol):
RuntimeWarning: invalid value encountered in subtract

======================================================================
ERROR: Failure: ImportError (cannot import name common_info)
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/failure.py", line 37, in runTest
   raise self.exc_class(self.exc_val).with_traceback(self.tb)
 File "/usr/lib/python3.2/site-packages/nose/loader.py", line 390, in
loadTestsFromName
   addr.filename, addr.module)
 File "/usr/lib/python3.2/site-packages/nose/importer.py", line 39,
in importFromPath
   return self.importFromDir(dir_path, fqname)
 File "/usr/lib/python3.2/site-packages/nose/importer.py", line 86,
in importFromDir
   mod = load_module(part_fqname, fh, filename, desc)
 File "/usr/lib64/python3.2/site-packages/scipy/weave/__init__.py",
line 26, in <module>
   from .inline_tools import inline
 File "/usr/lib64/python3.2/site-packages/scipy/weave/inline_tools.py",
line 5, in <module>
   from . import ext_tools
 File "/usr/lib64/python3.2/site-packages/scipy/weave/ext_tools.py",
line 7, in <module>
   from . import converters
 File "/usr/lib64/python3.2/site-packages/scipy/weave/converters.py",
line 4, in <module>
   from . import common_info
ImportError: cannot import name common_info

======================================================================
FAIL: test_mio.test_mat4_3d
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib/python3.2/site-packages/nose/case.py", line 198, in runTest
   self.test(*self.arg)
 File "/usr/lib64/python3.2/site-packages/scipy/io/matlab/tests/test_mio.py",
line 740, in test_mat4_3d
   stream, {'a': arr}, True, '4')
 File "/usr/lib64/python3.2/site-packages/numpy/testing/utils.py",
line 1008, in assert_raises
   return nose.tools.assert_raises(*args,**kwargs)
AssertionError: DeprecationWarning not raised by
functools.partial(<function savemat at 0x9e482f8>, oned_as='row')

======================================================================
FAIL: Regression test for #651: better handling of badly conditioned
----------------------------------------------------------------------
Traceback (most recent call last):
 File "/usr/lib64/python3.2/site-packages/scipy/signal/tests/test_filter_design.py",
line 34, in test_bad_filter
   assert_raises(BadCoefficients, tf2zpk, [1e-15], [1.0, 1.0])
 File "/usr/lib64/python3.2/site-packages/numpy/testing/utils.py",
line 1008, in assert_raises
   return nose.tools.assert_raises(*args,**kwargs)
AssertionError: BadCoefficients not raised by tf2zpk

----------------------------------------------------------------------

The NumPy errors seem to be mostly rounding errors, but it seems to
round quite aggressively. How siginificant are these errors?

.. Mads
_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
Denis Laxalde | 1 Feb 16:37
Picon

Re: NumPy and SciPy test failures

Mads M. Hansen wrote:
> I have built NumPy 1.6.1 and SciPy 0.10.0 for Python 3.2 on a Fedora
> 16 system and I used gfortran, but when I run the tests I get the
> following failures and errors

It's probably not scipy 0.10.0. Could you specify the exact versions of
you have installed (e.g. from the header displayed by scipy tests)?

> And SciPy:
> 
> ======================================================================
> ERROR: Failure: ImportError (cannot import name _minimize_neldermead)
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/usr/lib/python3.2/site-packages/nose/failure.py", line 37, in runTest
>     raise self.exc_class(self.exc_val).with_traceback(self.tb)
>   File "/usr/lib/python3.2/site-packages/nose/loader.py", line 390, in
> loadTestsFromName
>     addr.filename, addr.module)
>   File "/usr/lib/python3.2/site-packages/nose/importer.py", line 39,
> in importFromPath
>     return self.importFromDir(dir_path, fqname)
>   File "/usr/lib/python3.2/site-packages/nose/importer.py", line 86,
> in importFromDir
>     mod = load_module(part_fqname, fh, filename, desc)
>   File "/usr/lib64/python3.2/site-packages/scipy/optimize/tests/test_anneal.py",
> line 10, in <module>
>     from scipy.optimize import anneal, minimize
>   File "/usr/lib64/python3.2/site-packages/scipy/optimize/minimize.py",
> line 16, in <module>
>     from .optimize import _minimize_neldermead, _minimize_powell, \
> ImportError: cannot import name _minimize_neldermead

I was interested by this one but cannot reproduce it with current
master on python 3.2.2.

--

-- 
Denis
glen@toadhill.net | 1 Feb 17:16

asarray_chkfinite

Hi all,

I'm trying to optimize some code that entails a very large number of sparse matrix-vector and vctor-vector multiplies. Upon running the profiler I see that about 25% of my program's cumulative time is spent running asarray_chkfinite.  I do not call this routine directly. Can anyone tell me what might be calling it and whether there is anything obvious I can do about it?

Glen



Glen Henshaw, PhD • Roboticist • U.S. Naval Research Laboratory
office: 202-767-1196 • google voice/mobile: 443-295-3050
_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
Mads M. Hansen | 1 Feb 17:17
Picon

Re: NumPy and SciPy test failures

2012/2/1 Denis Laxalde <dlaxalde <at> gmail.com>:
> Mads M. Hansen wrote:
>> I have built NumPy 1.6.1 and SciPy 0.10.0 for Python 3.2 on a Fedora
>> 16 system and I used gfortran, but when I run the tests I get the
>> following failures and errors
>
> It's probably not scipy 0.10.0. Could you specify the exact versions of
> you have installed (e.g. from the header displayed by scipy tests)?
>
Here is the header

>>> scipy.test('full')
Running unit tests for scipy
NumPy version 1.6.1
NumPy is installed in /usr/lib64/python3.2/site-packages/numpy
SciPy version 0.10.0
SciPy is installed in /usr/lib64/python3.2/site-packages/scipy
Python version 3.2.1 (default, Jul 11 2011, 18:54:42) [GCC 4.6.1
20110627 (Red Hat 4.6.1-1)]
nose version 1.1.2

I checked out the v.0.10.0 tag from the Git repository.

.. Mads
Fabien Lafont | 1 Feb 17:21
Picon

[scipy-user] How to add a 1D np.array to another np.array?

Hello everyone,

I try to add an array to another (to build a 2D array).

I try that

a = np.zeros(2)
b=np.array([2,4])
a[[0]] = b

print a
[2,0]

And I want a= [[2,4],0]

How can I do?
Thx
Fabien
Alexander Kalinin | 1 Feb 17:34
Picon

Re: Accumulation sum using indirect indexes

Yes, but for large data sets loops is quite slow. I have tried Pandas groupby.sum() and it works faster.

2012/2/1 Frédéric Bastien <nouiz <at> nouiz.org>

It will be slow, but you can make a python loop.

Fred

On Jan 31, 2012 3:34 PM, "Alexander Kalinin" <alec.kalinin <at> gmail.com> wrote:
Hello!

I use SciPy in computer graphics applications. My task is to calculate vertex normals by averaging faces normals. In other words I want to accumulate vectors with the same ids. For example,

ids = numpy.array([0, 1, 1, 2])
n = numpy.array([ [0.1, 0.1, 0.1], [0.1, 0.1, 0.1], [0.1, 0.1, 0.1], [0.1, 0.1 0.1] ])

I need result:
nv = ([ [0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.1, 0.1, 0.1]])

The most simple code:
nv[ids] += n
does not work, I know about this. For 1D arrays I use numpy.bincount(...) function. But this function does not work for 2D arrays.

So, my question. What is the best way calculate accumulation sum for 2D arrays using indirect indexes?

Sincerely,
Alexander

_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user


_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user


_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user
Warren Weckesser | 1 Feb 17:35
Gravatar

Re: [scipy-user] How to add a 1D np.array to another np.array?



On Wed, Feb 1, 2012 at 10:21 AM, Fabien Lafont <lafont.fabien <at> gmail.com> wrote:
Hello everyone,

I try to add an array to another (to build a 2D array).

I try that



a = np.zeros(2)
b=np.array([2,4])
a[[0]] = b

print a
[2,0]

And I want a= [[2,4],0]


But that is not a 2D array.  Do you want to "stack" b above the zeros?  Perhaps something like this:

In [7]: a = np.zeros(2)

In [8]: b = np.array([2,4])

In [9]: c = np.vstack((b,a))

In [10]: c
Out[10]:
array([[ 2.,  4.],
       [ 0.,  0.]])


Warren

_______________________________________________
SciPy-User mailing list
SciPy-User <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-user

Gmane