Re: [Numpy-discussion] offset in fill diagonal

2017-01-21 Thread Ian Henriksen
On Sat, Jan 21, 2017 at 9:23 AM Julian Taylor 
wrote:

> On 21.01.2017 16:10, josef.p...@gmail.com wrote:
> > Is there a simple way to fill in diagonal elements in an array for other
> > than main diagonal?
> >
> > As far as I can see, the diagxxx functions that have offset can only
> > read and not inplace modify, and the functions for modifying don't have
> > offset and only allow changing the main diagonal.
> >
> > Usecase: creating banded matrices (2-D arrays) similar to toeplitz.
> >
>
> you can construct index arrays or boolean masks to index using the
> np.tri* functions.
> e.g.
>
> a = np.arange(5*5).reshape(5,5)
> band = np.tri(5, 5, 1, dtype=np.bool) & ~np.tri(5, 5, -2, dtype=np.bool)
> a[band] = -1
> ___
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion


You can slice the array you're filling before passing it to fill_diagonal.
For example:

import numpy as np
a = np.zeros((4, 4))
b = np.ones(3)
np.fill_diagonal(a[1:], b)
np.fill_diagonal(a[:,1:], -b)

yields

array([[ 0., -1.,  0.,  0.],
   [ 1.,  0., -1.,  0.],
   [ 0.,  1.,  0., -1.],
   [ 0.,  0.,  1.,  0.]])

Hope this helps,

Ian Henriksen
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] offset in fill diagonal

2017-01-21 Thread Julian Taylor
On 21.01.2017 16:10, josef.p...@gmail.com wrote:
> Is there a simple way to fill in diagonal elements in an array for other
> than main diagonal?
> 
> As far as I can see, the diagxxx functions that have offset can only
> read and not inplace modify, and the functions for modifying don't have
> offset and only allow changing the main diagonal.
> 
> Usecase: creating banded matrices (2-D arrays) similar to toeplitz.
> 

you can construct index arrays or boolean masks to index using the
np.tri* functions.
e.g.

a = np.arange(5*5).reshape(5,5)
band = np.tri(5, 5, 1, dtype=np.bool) & ~np.tri(5, 5, -2, dtype=np.bool)
a[band] = -1
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] offset in fill diagonal

2017-01-21 Thread josef . pktd
Is there a simple way to fill in diagonal elements in an array for other
than main diagonal?

As far as I can see, the diagxxx functions that have offset can only read
and not inplace modify, and the functions for modifying don't have offset
and only allow changing the main diagonal.

Usecase: creating banded matrices (2-D arrays) similar to toeplitz.


Josef
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] Building external c modules with mingw64 / numpy

2017-01-21 Thread Schnizer, Pierre
Dear all,

   I built  an external c-module (pygsl) using mingw 64 from msys2 
mingw64-gcc compiler.

This  built required  some changes  to numpy.distutils to get the
“python setup.py config”
and
“python setup.py build”
working. In this process  I replaced  2 files in numpy.distutils  from numpy 
git repository:

-  numpy.dist_utils.misc_utils.py version ec0e046 

 on 14 Dec 2016

-  numpy.dist_utils. mingw32ccompiler.py version ec0e046 

 on 14 Dec 2016

mingw32ccompiler.py required to be modified to get it work

n  preprocessor  had to be defined  as I am using  setup.py config

n  specifying the runtime library search path to the linker

n  include path  of the vcrtruntime

I attached a patch reflecting the changes  I had to make  to file 
mingw32ccompile.py
If this information is useful I am  happy to answer questions

Sincerely yours
   Pierre

PS  Version infos:
Python:
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit 
(AMD64)] on win32

Numpy:
>> help(numpy.version)
Help on module numpy.version in numpy:
DATA
full_version = '1.12.0'
git_revision = '561f1accf861ad8606ea2dd723d2be2b09a2dffa'
release = True
short_version = '1.12.0'
version = '1.12.0'

gcc.exe (Rev2, Built by MSYS2 project) 6.2.0





Helmholtz-Zentrum Berlin für Materialien und Energie GmbH

Mitglied der Hermann von Helmholtz-Gemeinschaft Deutscher Forschungszentren e.V.

Aufsichtsrat: Vorsitzender Dr. Karl Eugen Huthmacher, stv. Vorsitzende Dr. 
Jutta Koch-Unterseher
Geschäftsführung: Prof. Dr. Anke Rita Kaysser-Pyzalla, Thomas Frederking

Sitz Berlin, AG Charlottenburg, 89 HRB 5583

Postadresse:
Hahn-Meitner-Platz 1
D-14109 Berlin

http://www.helmholtz-berlin.de


python_numpy_mingw_git.diff
Description: python_numpy_mingw_git.diff
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
https://mail.scipy.org/mailman/listinfo/numpy-discussion