[Numpy-discussion] two dimensional array of sets

gerardob gberbeglia at gmail.com
Thu Aug 12 17:54:06 EDT 2010


As i wrote, the elements of each A[i][j] are sets and not numbers.


David Warde-Farley-2 wrote:
> 
> On 2010-08-12, at 3:59 PM, gerardob wrote:
> 
>> 
>> Hello, this is a very basic question but i don't know the answer.
>> 
>> I would like to construct a two dimensional array A, such that A[i][j]
>> contains a set of numbers associated to the pair (i,j). For example,
>> A[i][j]
>> can be all the numbers that are written as i^n*j*5-n for some all
>> n=1,..,5
>> 
>> Is numpy what i need? if not which is the way to define such arrays. I
>> mean,
>> how do i declare an 2-dimensional array of a given size (for after start
>> filling it with specific sets)?
> 
> The easiest way to do this would be
> 
>>>> import numpy as np
>>>> n = 2
>>>> i, j = np.ogrid[1:6, 1:6]
>>>> arr = i**n * j*5 - n
>>>> print arr
> array([[  3,   8,  13,  18,  23],
>        [ 18,  38,  58,  78,  98],
>        [ 43,  88, 133, 178, 223],
>        [ 78, 158, 238, 318, 398],
>        [123, 248, 373, 498, 623]])
> 
> David
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
> 
> 

-- 
View this message in context: http://old.nabble.com/two-dimensional-array-of-sets-tp29422693p29423645.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.




More information about the NumPy-Discussion mailing list