Re: [Numpy-discussion] 100 Numpy exercices

2014-05-27 Thread Nicolas Rougier
On 27 May 2014, at 21:09, Chris Barker chris.bar...@noaa.gov wrote: On Mon, May 26, 2014 at 9:57 PM, Nicolas Rougier nicolas.roug...@inria.fr wrote: I've updated the numpy exercices collection and made it available on github at: https://github.com/rougier/numpy-100 very useful

Re: [Numpy-discussion] 100 Numpy exercices

2014-05-27 Thread Nicolas Rougier
Thanks, you just inaugurated the master section. Nicolas On 27 May 2014, at 21:48, Jaime Fernández del Río jaime.f...@gmail.com wrote: On Tue, May 27, 2014 at 12:27 PM, Nicolas Rougier nicolas.roug...@inria.fr wrote: Any other tricky stride_trick tricks ? I promised to put them

[Numpy-discussion] 100 Numpy exercices

2014-05-26 Thread Nicolas Rougier
Hi all, I've updated the numpy exercices collection and made it available on github at: https://github.com/rougier/numpy-100 These exercices mainly comes from this mailing list and also from stack overflow. If you have other examples in mind, do not hesitate to make a pull request. The

Re: [Numpy-discussion] python array

2014-03-13 Thread Nicolas Rougier
Seems to be related to the masked values: print r2010[:3,:3] [[-- -- --] [-- -- --] [-- -- --]] print abs(r2010)[:3,:3] [[-- -- --] [-- -- --] [-- -- --]] print r2010[ r2010[:3,:3] 0 ] [-- -- -- -- -- -- -- -- --] print r2010[ abs(r2010)[:3,:3] 0] [] Nicolas On 13 Mar 2014, at

[Numpy-discussion] dtype promotion

2014-03-03 Thread Nicolas Rougier
Hi all, I'm using numpy 1.8.0 (osx 10.9, python 2.7.6) and I can't understand dtype promotion in the following case: Z = np.zeros((2,2),dtype=np.float32) + 1 print Z.dtype float32 Z = np.zeros((2,2),dtype=np.float32) + (1,1) print Z.dtype float64 Is this the expected behavior ? What it

Re: [Numpy-discussion] dtype promotion

2014-03-03 Thread Nicolas Rougier
On Mon, Mar 3, 2014 at 4:06 PM, Nicolas Rougier nicolas.roug...@inria.fr wrote: Hi all, I'm using numpy 1.8.0 (osx 10.9, python 2.7.6) and I can't understand dtype promotion in the following case: Z = np.zeros((2,2),dtype=np.float32) + 1 print Z.dtype float32 Z = np.zeros((2,2

[Numpy-discussion] Bug in resize of structured array (with initial size = 0)

2014-01-10 Thread Nicolas Rougier
Hi, I've tried to resize a record array that was first empty (on purpose, I need it) and I got the following error (while it's working for regular array). Traceback (most recent call last): File test_resize.py, line 10, in module print np.resize(V,2) File

[Numpy-discussion] ArrayList object

2014-01-04 Thread Nicolas Rougier
Hi all, I've coding an ArrayList object based on a regular numpy array. This objects allows to dynamically append/insert/delete/access items. I found it quite convenient since it allows to manipulate an array as if it was a list with elements of different sizes but with same underlying type

Re: [Numpy-discussion] Structured array dtype

2013-08-31 Thread Nicolas Rougier
= np.zeros(10, (np.float32,4)) Z.strides (16,4) Nicolas On Aug 31, 2013, at 7:51 AM, Stéfan van der Walt ste...@sun.ac.za wrote: Hi Nicolas On Fri, 30 Aug 2013 17:26:51 +0200, Nicolas Rougier wrote: Z = np.zeros(10, [('a', np.float32, 3), ('b', np.float32, 4)]) Z['a'].dtype dtype

[Numpy-discussion] Structured array dtype

2013-08-30 Thread Nicolas Rougier
Hi, I'm a bit lost with the following example (numpy 1.7.1, osx 10.8): Z = np.zeros(10, [('a', np.float32, 3), ('b', np.float32, 4)]) Z['a'].dtype dtype('float32') Z.dtype['a'] dtype(('f4', (3,))) Does that mean that dtype['a'] is the dtype of field 'a' when in Z, while Z['a'].dtype is

[Numpy-discussion] Using as_strided to avoid copy on repeat (with 2-dimensional array)

2013-08-12 Thread Nicolas Rougier
Hi, I have a (n,2) shaped array representing points and I would like to double each point as in: A = np.arange(10*2).reshape(10,2) B = np.repeat( A, 2, axis=0 ) Is it possible to do the same using 'as_strided' to avoid copy (and still get the same output shape for B) ? I found this

Re: [Numpy-discussion] np.dot and 'out' bug

2013-05-23 Thread Nicolas Rougier
Sure, that's clearly what's going on, but numpy shouldn't let you silently shoot yourself in the foot like that. Re-using input as output is a very common operation, and usually supported fine. Probably we should silently make a copy of any input(s) that overlap with the output? For

Re: [Numpy-discussion] np.dot and 'out' bug

2013-05-23 Thread Nicolas Rougier
Can you file a bug in the bug tracker so this won't get lost? Done. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

[Numpy-discussion] Possible conversion bug with record array

2013-05-22 Thread Nicolas Rougier
Hi all, I got a weird output from the following script: import numpy as np U = np.zeros(1, dtype=[('x', np.float32, (4,4))]) U[0] = np.eye(4) print U[0] # output: ([[0.0, 1.875, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 1.875], [0.0, 0.0, 0.0, 0.0]],) U[0] = np.eye(4,

Re: [Numpy-discussion] Possible conversion bug with record array

2013-05-22 Thread Nicolas Rougier
Thanks, I filed a new issue on the bug tracker. Nicolas On May 22, 2013, at 8:15 PM, eat e.antero.ta...@gmail.com wrote: Hi, FWIW, apparently bug related to dtype of np.eye(.) On Wed, May 22, 2013 at 8:07 PM, Nicolas Rougier nicolas.roug...@inria.fr wrote: Hi all, I got

[Numpy-discussion] Numpy beginner tutorial

2013-05-07 Thread Nicolas Rougier
Hello everybody, I've written a numpy beginner tutorial that is available from: http://www.loria.fr/~rougier/teaching/numpy/numpy.html It has been designed around cellular automata to try to make it fun. While writing it, I tried to compile a set of exercises and make them progressively

Re: [Numpy-discussion] GSOC 2013

2013-03-04 Thread Nicolas Rougier
This made me think of a serious performance limitation of structured dtypes: a structured dtype is always packed, which may lead to terrible byte alignment for common types. For instance, `dtype([('a', 'u1'), ('b', 'u8')]).itemsize == 9`, meaning that the 8-byte integer is not aligned as an

Re: [Numpy-discussion] Array indexing and repeated indices

2013-03-01 Thread Nicolas Rougier
bincount takes a weights argument which should do exactly what you are looking for. Fantastic ! Thanks ! Nicolas ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

[Numpy-discussion] Array indexing and repeated indices

2013-02-28 Thread Nicolas Rougier
Hi, I'm trying to increment an array using indexing and a second array for increment values (since it might be a little tedious to explain, see below for a short example). Using direct indexing, the values in the example are incremented by 1 only while I want to achieve the alternative

[Numpy-discussion] View on sliced array without copy

2013-02-12 Thread Nicolas Rougier
Hi, I'm trying to get a view on a sliced array without copy but I'm not able to do it as illustrated below: dtype = np.dtype( [('color', 'f4', 4)] ) Z = np.zeros(100, dtype=dtype) print Z.view('f4').base is Z# True print Z[:50].base is Z # True print

Re: [Numpy-discussion] View on sliced array without copy

2013-02-12 Thread Nicolas Rougier
I did not know that. Thanks for the clear explanation. Nicolas On Feb 12, 2013, at 19:25 , Jaime Fernández del Río wrote: On Tue, Feb 12, 2013 at 9:53 AM, Nicolas Rougier nicolas.roug...@inria.fr wrote: Did I do something wrong or is it expected behavior ? Try: print (Z.view('f4

Re: [Numpy-discussion] dtype reduction [SOLVED]

2013-01-15 Thread Nicolas Rougier
) On Dec 27, 2012, at 9:11 , Nicolas Rougier wrote: Yep, I'm trying to construct dtype2 programmaticaly and was hoping for some function giving me a canonical expression of the dtype. I've started playing with fields but it's just a bit harder than I though (lot of different cases

Re: [Numpy-discussion] Manipulate neighboring points in 2D array

2012-12-30 Thread Nicolas Rougier
You might want to have a look at : http://code.google.com/p/glumpy/source/browse/demos/gray-scott.py which implements a Gray-Scott reaction-diffusion system. The 'convolution_matrix(src, dst, kernel, toric)' build a sparse matrix such that multiplying an array with this matrix will result in

Re: [Numpy-discussion] dtype reduction

2012-12-27 Thread Nicolas Rougier
, 2012, at 1:32 , Nathaniel Smith wrote: On Wed, Dec 26, 2012 at 8:09 PM, Nicolas Rougier nicolas.roug...@inria.fr wrote: Hi all, I'm looking for a way to reduce dtype1 into dtype2 (when it is possible of course). Is there some easy way to do that by any chance ? dtype1 = np.dtype

[Numpy-discussion] dtype reduction

2012-12-26 Thread Nicolas Rougier
Hi all, I'm looking for a way to reduce dtype1 into dtype2 (when it is possible of course). Is there some easy way to do that by any chance ? dtype1 = np.dtype( [ ('vertex', [('x', 'f4'), ('y', 'f4'), ('z', 'f4')]),

Re: [Numpy-discussion] [numpy] ENH: Initial implementation of a 'neighbor' calculation (#303)

2012-10-12 Thread Nicolas Rougier
Sorry, I'm away from the lab and did not have a chance to test is yet. I will do next week. Nicolas On Oct 11, 2012, at 15:48 , Nathaniel Smith wrote: On Thu, Oct 11, 2012 at 10:50 AM, Nicolas Rougier nicolas.roug...@inria.fr wrote: I missed the original post but I personally find

Re: [Numpy-discussion] [numpy] ENH: Initial implementation of a 'neighbor' calculation (#303)

2012-10-11 Thread Nicolas Rougier
I missed the original post but I personally find this addition especially useful for my work in computational neuroscience. I did something vaguely similar in a small framework (http://dana.loria.fr/, you can look more specifically at http://dana.loria.fr/doc/connection.html for details).

Re: [Numpy-discussion] Matrices and arrays of vectors

2012-02-24 Thread Nicolas Rougier
You should use a (M,N,2) array to store your vectors: import math import numpy import numpy.random # Rotation angle theta = math.pi/6.0 # Grid shape M = 10 N = 10 # Establish the rotation matrix c = math.cos(theta) s = math.sin(theta) rotation = numpy.array([[c, s],

Re: [Numpy-discussion] [ANN] glumpy 0.2.0

2011-09-17 Thread Nicolas Rougier
Thanks. I just uploaded it to pypi. Nicolas On Sep 16, 2011, at 22:21 , Samuel John wrote: Hi Nicolas, that looks great. Could you make this available such that `pip install glumpy` would work? cheers, Samuel ___ NumPy-Discussion

[Numpy-discussion] [ANN] glumpy 0.2.0

2011-09-16 Thread Nicolas Rougier
Hi folks, I am pleased to announce a new release of glumpy, a small python library for the (very) fast vizualization of numpy arrays, (mainly two dimensional) that has been designed with efficiency in mind. If you want to draw nice figures for inclusion in a scientific article, you’d better

Re: [Numpy-discussion] Recommndations for an easy GUI

2011-06-28 Thread Nicolas Rougier
Have a look at glumpy: http://code.google.com/p/glumpy/ It's quite simple and very fast for images (it's based on OpenGL/shaders). Nicolas On Jun 28, 2011, at 6:38 AM, Nadav Horesh wrote: I have an application which generates and displays RGB images as rate of several frames/seconds

Re: [Numpy-discussion] Viewer for 2D Numpy arrays (GUI)

2010-09-17 Thread Nicolas Rougier
Maybe glumpy may be of some help: http://code.google.com/p/glumpy/ Nicolas On Fri, 2010-09-17 at 09:03 +0200, Massimo Di Stefano wrote: Hi, have yo already tryied Spyderlib : http://code.google.com/p/spyderlib/ a matlab-like environment based on pyqt you can store object

[Numpy-discussion] Help on vectorization of mesh normals computation

2010-06-17 Thread Nicolas Rougier
Hello, I'm trying to find a way to compute the normals of a mesh (vertices + indices) using only vectorized computations and I wonder if anyone already did that. Here my code so far: # Mesh generation + indices for triangles n = 24 vertices = numpy.zeros(((n*n),3), dtype=numpy.float32)

Re: [Numpy-discussion] Some help on matlab to numpy translation

2010-03-15 Thread Nicolas Rougier
Thanks and in fact, I already wasted quite some time on and your last version will help me a lot. Unfortunately, I'm not a specialist at lattice Boltzmann methods at all so I'm not able to answer your questions (my initial idea was to convert the matlab script to be have a running example to

Re: [Numpy-discussion] Some help on matlab to numpy translation

2010-03-14 Thread Nicolas Rougier
(), u.max() #plt.imshow(u) #plt.show() On Mar 13, 2010, at 16:59 , Friedrich Romstedt wrote: 2010/3/13 Nicolas Rougier nicolas.roug...@loria.fr: I'm trying to translate a small matlab program for the simulation in a 2D flow in a channel past a cylinder and since I do not have matlab

[Numpy-discussion] Some help on matlab to numpy translation

2010-03-13 Thread Nicolas Rougier
Hello, I'm trying to translate a small matlab program for the simulation in a 2D flow in a channel past a cylinder and since I do not have matlab access, I would like to know if someone can help me, especially on array indexing. The matlab source code is available at:

Re: [Numpy-discussion] Some help on matlab to numpy translation

2010-03-13 Thread Nicolas Rougier
Thanks. I agree that the use of ':' is a bit weird. Nicolas On Mar 13, 2010, at 11:45 , Fabrice Silva wrote: Le samedi 13 mars 2010 à 10:20 +0100, Nicolas Rougier a écrit : Hello, I'm trying to translate a small matlab program for the simulation in a 2D flow in a channel past a cylinder

[Numpy-discussion] glumpy, fast opengl visualization

2010-01-25 Thread Nicolas Rougier
Hello, This is an update about glumpy, a fast-OpenGL based numpy visualization. I modified the code such that the only dependencies are PyOpenGL and IPython (for interactive sessions). You will also need matplotlib and scipy for some demos. Sources: hg clone http://glumpy.googlecode.com/hg/

[Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Nicolas Rougier
Hello, Using both numpy 1.3.0 and 1.4.0rc1 I got the following exception using nan_to_num on a bool array, is that the expected behavior ? import numpy Z = numpy.zeros((3,3),dtype=bool) numpy.nan_to_num(Z) Traceback (most recent call last): File stdin, line 1, in module File

Re: [Numpy-discussion] nan_to_num and bool arrays

2009-12-11 Thread Nicolas Rougier
I've created a ticket (#1327). Nicolas On Dec 11, 2009, at 17:21 , Keith Goodman wrote: On Fri, Dec 11, 2009 at 12:50 AM, Nicolas Rougier nicolas.roug...@loria.fr wrote: Hello, Using both numpy 1.3.0 and 1.4.0rc1 I got the following exception using nan_to_num on a bool array

[Numpy-discussion] glumpy: fast OpenGL numpy visualization + matplotlib integration

2009-09-28 Thread Nicolas Rougier
Hi all, glumpy is a fast OpenGL visualization tool for numpy arrays coded on top of pyglet (http://www.pyglet.org/). The package contains many demos showing basic usage as well as integration with matplotlib. As a reference, the animation script available from matplotlib distribution

Re: [Numpy-discussion] [Matplotlib-users] glumpy: fast OpenGL numpy visualization + matplotlib integration

2009-09-28 Thread Nicolas Rougier
is whether people are interested in glumpy to have a quick dirty debug tool on top of matplotlib or whether they prefer a full fledged and fast pyglet/OpenGL backend (which is really harder). Nicolas On 28 Sep, 2009, at 18:05 , Gökhan Sever wrote: On Mon, Sep 28, 2009 at 9:06 AM, Nicolas

[Numpy-discussion] Recipe: extract a sub-array using given shape, centered on given position

2009-08-19 Thread Nicolas Rougier
Hi, I've coded a function that allows to extract a contiguous array from another one using a given shape and centered on a given position. I did not find an equivalent within numpy so I hope I did not miss it. The only interest of the function is to guarantee that the resulting sub-array

Re: [Numpy-discussion] Memory layout of record arrays

2009-07-31 Thread Nicolas Rougier
at 20:01 +0200, Nicolas Rougier wrote: Thanks for the quick answer. It makes sense. I will have to find some other way to do it then. Nicolas On 30 Jul, 2009, at 18:52 , David Cournapeau wrote: On Fri, Jul 31, 2009 at 12:53 AM, Nicolas Rougiernicolas.roug...@loria.fr wrote

[Numpy-discussion] Memory layout of record arrays

2009-07-30 Thread Nicolas Rougier
Hello, I've been using record arrays to create arrays with different types and since I'm doing a lot of computation on each of the different fields, the default memory layout does not serve my computations. Ideally, I would like to have record arrays where each field is a contiguous

Re: [Numpy-discussion] Memory layout of record arrays

2009-07-30 Thread Nicolas Rougier
Thanks for the quick answer. It makes sense. I will have to find some other way to do it then. Nicolas On 30 Jul, 2009, at 18:52 , David Cournapeau wrote: On Fri, Jul 31, 2009 at 12:53 AM, Nicolas Rougiernicolas.roug...@loria.fr wrote: Hello, I've been using record arrays to create

Re: [Numpy-discussion] sparse matrix dot product

2009-05-29 Thread Nicolas Rougier
Hi, I tried to post results but the file is too big, anyway, here is the benchmark program if you want to run it: Nicolas - import time import numpy from scipy import sparse def benchmark(xtype = 'numpy.array', xdensity = 0.1, ytype = 'numpy.array', ydensity = 1.0, n =

Re: [Numpy-discussion] Benchmak on record arrays

2009-05-29 Thread Nicolas Rougier
Thank for the clear answer, it definitely helps. Nicolas On Thu, 2009-05-28 at 19:25 +0200, Francesc Alted wrote: A Wednesday 27 May 2009 17:31:20 Nicolas Rougier escrigué: Hi, I've written a very simple benchmark on recarrays: import numpy, time Z = numpy.zeros((100,100

[Numpy-discussion] sparse matrix dot product

2009-05-28 Thread Nicolas Rougier
Hi, I'm now testing dot product and using the following: import numpy as np, scipy.sparse as sp A = np.matrix(np.zeros((5,10))) B = np.zeros((10,1)) print (A*B).shape print np.dot(A,B).shape A = sp.csr_matrix(np.zeros((5,10))) B = sp.csr_matrix((10,1)) print (A*B).shape print

[Numpy-discussion] Benchmak on record arrays

2009-05-27 Thread Nicolas Rougier
Hi, I've written a very simple benchmark on recarrays: import numpy, time Z = numpy.zeros((100,100), dtype=numpy.float64) Z_fast = numpy.zeros((100,100), dtype=[('x',numpy.float64), ('y',numpy.int32)]) Z_slow = numpy.zeros((100,100), dtype=[('x',numpy.float64), ('y',numpy.bool)]) t =

Re: [Numpy-discussion] Benchmak on record arrays

2009-05-27 Thread Nicolas Rougier
No, I don't have permission to edit. Nicolas On 27 May, 2009, at 18:01 , Charles R Harris wrote: On Wed, May 27, 2009 at 9:31 AM, Nicolas Rougier nicolas.roug...@loria.fr wrote: Hi, I've written a very simple benchmark on recarrays: import numpy, time Z = numpy.zeros((100,100

[Numpy-discussion] arrray/matrix nonzero() type

2009-05-27 Thread Nicolas Rougier
Hi again, I have a problem with the nonzero() function for matrix. The following test program: import numpy, scipy.sparse Z = numpy.zeros((10,10)) Z[0,0] = Z[1,1] = 1 i = Z.nonzero() print i Zc = scipy.sparse.coo_matrix((Z[i],i)) Z = numpy.matrix(Z) i = Z.nonzero() print i Zc =

[Numpy-discussion] Segmentation fault on large arrays

2009-05-26 Thread Nicolas Rougier
Hello, I've come across what is probably a bug in size check for large arrays: import numpy z1 = numpy.zeros((255*256,256*256)) Traceback (most recent call last): File stdin, line 1, in module ValueError: dimensions too large. z2 = numpy.zeros((256*256,256*256)) z2.shape (65536, 65536)

[Numpy-discussion] Tensordot and memory consumption

2009-02-17 Thread Nicolas Rougier
Hello, I'm using tensordot in some computation and while I've been amazed by the speed, I'm now trying to reduce memory consumption in some very particular cases: Let S be a 2 dims array of size (s1,s2) Let D be a 2 dims array of size (d1,d2) Let W be a 4 dims array of size (d1,d2,s1,s2)

Re: [Numpy-discussion] python user defined type

2008-07-11 Thread Nicolas Rougier
something like: group = Unit()*[2,2] group.potentials = numpy.zeros([2,2]) print group.potentials [[ 0. 0.] [ 0. 0.]] group[0,0].potential = 1 [[ 1. 0.] [ 0. 0.]] Nicolas On Thu, 2008-07-10 at 16:30 -0700, Christopher Barker wrote: Nicolas Rougier wrote: Concerning the dtype

Re: [Numpy-discussion] python user defined type

2008-07-10 Thread Nicolas Rougier
, Christopher Barker wrote: Nicolas Rougier wrote: I would like to create numpy array with my own (python) datatype, so I tried the obvious solution: from numpy import * class Unit(object): def __init__(self,value=0.0): self.value = value def __float__(self