"KraftDiner" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Thank you that worked great!
>
> a = [[None] * 256] * 256
> for i in range(0,256):
> for j in range(0,256):
> a[i][j] = i**2
>
> Now.. Can I change this quickly into a 1 dimensional list of length
> 65536?
If 'a' were a N
# Nested list comprehensions act like real for loops:
>>> a = [[None for i in range(3)] for j in range(3)]
>>> a
[[None, None, None], [None, None, None], [None, None, None]]
>>> a[0][0] = 5
>>> a
[[5, None, None], [None, None, None], [None, None, None]]
# Side-effect: i and j will be changed.
# An
How about:
a = [ [i**2 for j in range(256)] for i in range(256) ]
b = sum(a, [])
c = [ b[slice(i,i+256)] for i in range(0,256*256,256) ]
>>> a is c
False
>>> a == c
True
BranoZ
--
http://mail.python.org/mailman/listinfo/python-list
KraftDiner wrote:
> nope.. sorry its not...
> I meant x = [[1,2,3],[3,4,5],[5,6,7]]
>
Whew, you were about to really throw me for a loop otherwise! :)
--
http://mail.python.org/mailman/listinfo/python-list
John Salerno wrote:
> KraftDiner wrote:
>
>> [[1][2][3], [4][5][6], [7][8][9]]
>
> I'm confused. Is that a valid list?
No. I'm assuming he meant [[1, 2, 3], [4, 5, 6], [7, 8, 9]].
--
http://mail.python.org/mailman/listinfo/python-list
nope.. sorry its not...
I meant x = [[1,2,3],[3,4,5],[5,6,7]]
--
http://mail.python.org/mailman/listinfo/python-list
Oh by the way the b = sum(a, []) worked well to convert the two
dimensional array to a 1D array...
Is there a way to bring that 1D array back to a 2D array?
--
http://mail.python.org/mailman/listinfo/python-list
KraftDiner wrote:
> [[1][2][3], [4][5][6], [7][8][9]]
I'm confused. Is that a valid list?
--
http://mail.python.org/mailman/listinfo/python-list
Yes I missed the fine print that said that the code had 'side effects'
So:
a = [None]*256
for i in range(256):
a[i] = [None] * 256
for i in range(0,256):
for j in range(0,256):
a[i][j] = i**2
a = sum(a, [])
print a[0]
print a[65535]
--
http://mail.py
"KraftDiner" wrote:
> Strange behaviour...
>
> a = [[None] * 256] * 256
> for i in range(0,256):
> for j in range(0,256):
> a[i][j] = i**2
> a = sum(a, [])
> print a[0]
> print a[65535]
>
> Prints:
>
> 65025
> 65025
looks like you missed that the page I pointed you to explained *why*
the a = [[No
Strange behaviour...
a = [[None] * 256] * 256
for i in range(0,256):
for j in range(0,256):
a[i][j] = i**2
a = sum(a, [])
print a[0]
print a[65535]
Prints:
65025
65025
--
http://mail.python.org/mailman/listinfo/python-list
KraftDiner schrieb:
> Thank you that worked great!
>
> a = [[None] * 256] * 256
> for i in range(0,256):
> for j in range(0,256):
> a[i][j] = i**2
>
> Now.. Can I change this quickly into a 1 dimensional list of length
> 65536?
sum(a, [])
Diez
--
http://mail.python.org/ma
Thank you that worked great!
a = [[None] * 256] * 256
for i in range(0,256):
for j in range(0,256):
a[i][j] = i**2
Now.. Can I change this quickly into a 1 dimensional list of length
65536?
--
http://mail.python.org/mailman/listinfo/python-list
"KraftDiner" wrote:
> I need a matrix of 256 x 256 unsigned short values...
> The matrix can be implemented as a list of lists or a tuple...
> So for example:
> [[1][2][3], [4][5][6], [7][8][9]]
> or
> ((1,2,3),(4,5,6), (7,8,9))
>
> This is what I have so far but its not working...
>
> a = [][]
>
I need a matrix of 256 x 256 unsigned short values...
The matrix can be implemented as a list of lists or a tuple...
So for example:
[[1][2][3], [4][5][6], [7][8][9]]
or
((1,2,3),(4,5,6), (7,8,9))
This is what I have so far but its not working...
a = [][]
for i in range(0,256):
for j in r
15 matches
Mail list logo