Python论坛  - 讨论区

标题:Re: [python-chinese] 问关于三维数组在python中 的 表达

2005年05月01日 星期日 13:30

Qiangning Hong hongqn at gmail.com
Sun May 1 13:30:44 HKT 2005

[x] * 3 的意思是创建一个包含三个元素的list,其中每个元素都是x,也就是说这三个元素绑定的是同一个对象。

table = [[1]*3]*3 等价于:
a = [1, 1, 1]
table = [a, a, a]


On 5/1/05, William Wu <william at sinowish.com> wrote:
> 
> 的确,和解呢?
> 
> Qiangning Hong wrote:
> 
> > 这个构造出来的不是三维数组,修改其中一个元素就会导致其他元素发生变化。
> >
> > 例如:
> >
> > .>>> x = [[[1]*3]*3]*3
> > .>>> x
> > [[[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1, 1, 1]],
> > [[1, 1, 1], [1, 1, 1], [1, 1, 1]]]
> > .>>> x[1][1][1] = 2
> > .>>> x
> > [[[1, 2, 1], [1, 2, 1], [1, 2, 1]], [[1, 2, 1], [1, 2, 1], [1, 2, 1]],
> > [[1, 2, 1], [1, 2, 1], [1, 2, 1]]]
> >
> >
> >
> > On 5/1/05, *William Wu* <william at sinowish.com
> > william at sinowish.com>> wrote:
> >
> > [[[1]*12]*12]*12
> >
> > Qiangning Hong wrote:
> >
> > > On 5/1/05, *Qiangning Hong* <hongqn at gmail.com
> > hongqn at gmail.com>
> > > hongqn at gmail.com hongqn at gmail.com>>> wrote:
> > >
> > > On 5/1/05, *jawbreaker* <jawbreaker at 163.com
> > jawbreaker at 163.com>
> > > jawbreaker at 163.com jawbreaker at 163.com>>> wrote:
> > >
> > > 在C中,我们会这样定义和初始化这样一个三维数组:
> > > int Table[12][12][12];
> > > for(i=0;i<12;i++)
> > > for(j=0;j<12;j++)
> > > for(k=0;k<12;k++)
> > > Table[i][j][k]=1;
> > >
> > >
> > > Table = [[[[1] * 12] for x in range(12)] for x in range(12)]
> > >
> > >
> > > 不好意思,写错了,应该是:
> > > Table = [ [ [1] * 12 for x in range(12) ] for x in range(12) ]
> > >
> > > --
> > > Qiangning Hong
> > > Get Firefox!
> > > <
> > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
> > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>>>
> > >
> > 
> >------------------------------------------------------------------------
> > >
> > >_______________________________________________
> > >python-chinese list
> > > python-chinese at lists.python.cn
> > python-chinese at lists.python.cn>
> > >http://python.cn/mailman/listinfo/python-chinese
> > >
> > >
> >
> >
> >
> >
> >
> > --
> > Qiangning Hong
> > Get Firefox!
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
> 
> 
> 


-- 
Qiangning Hong
Get Firefox! <
http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050501/6a2c6d9f/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年05月01日 星期日 13:50

William Wu william at sinowish.com
Sun May 1 13:50:04 HKT 2005

但是为什么当 table[1][1]=2 的时候 Table 却成为
[[1, 2, 1], [1, 2, 1], [1, 2, 1]] 了呢?

匪夷所思



Qiangning Hong wrote:

> [x] * 3 的意思是创建一个包含三个元素的list,其中每个元素都是x,也就是
> 说这三个元素绑定的是同一个对象。
>
> table = [[1]*3]*3 等价于:
> a = [1, 1, 1]
> table = [a, a, a]
>
>
> On 5/1/05, *William Wu* <william at sinowish.com
> william at sinowish.com>> wrote:
>
>     的确,和解呢?
>
>     Qiangning Hong wrote:
>
>     > 这个构造出来的不是三维数组,修改其中一个元素就会导致其他元素发生
>     变化。
>     >
>     > 例如:
>     >
>     > .>>> x = [[[1]*3]*3]*3
>     > .>>> x
>     > [[[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1,
>     1, 1]],
>     > [[1, 1, 1], [1, 1, 1], [1, 1, 1]]]
>     > .>>> x[1][1][1] = 2
>     > .>>> x
>     > [[[1, 2, 1], [1, 2, 1], [1, 2, 1]], [[1, 2, 1], [1, 2, 1], [1,
>     2, 1]],
>     > [[1, 2, 1], [1, 2, 1], [1, 2, 1]]]
>     >
>     >
>     >
>     > On 5/1/05, *William Wu* <william at sinowish.com
>     william at sinowish.com>
>     > william at sinowish.com william at sinowish.com>>> wrote:
>     >
>     > [[[1]*12]*12]*12
>     >
>     > Qiangning Hong wrote:
>     >
>     > > On 5/1/05, *Qiangning Hong* <hongqn at gmail.com
>     hongqn at gmail.com>
>     > hongqn at gmail.com hongqn at gmail.com>>
>     > > hongqn at gmail.com hongqn at gmail.com>
>     hongqn at gmail.com hongqn at gmail.com>>>> wrote:
>     > >
>     > > On 5/1/05, *jawbreaker* < jawbreaker at 163.com
>     jawbreaker at 163.com>
>     > jawbreaker at 163.com jawbreaker at 163.com>>
>     > > jawbreaker at 163.com jawbreaker at 163.com>
>     jawbreaker at 163.com jawbreaker at 163.com>>>> wrote:
>     > >
>     > > 在C中,我们会这样定义和初始化这样一个三维数组:
>     > > int Table[12][12][12];
>     > > for(i=0;i<12;i++)
>     > > for(j=0;j<12;j++)
>     > > for(k=0;k<12;k++)
>     > > Table[i][j][k]=1;
>     > >
>     > >
>     > > Table = [[[[1] * 12] for x in range(12)] for x in range(12)]
>     > >
>     > >
>     > > 不好意思,写错了,应该是:
>     > > Table = [ [ [1] * 12 for x in range(12) ] for x in range(12) ]
>     > >
>     > > --
>     > > Qiangning Hong
>     > > Get Firefox!
>     > > <
>     > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
>     > <
>     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
>     > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
>     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>
>     > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
>     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>>>>
>     > >
>     >
>     >------------------------------------------------------------------------
>
>     > >
>     > >_______________________________________________
>     > >python-chinese list
>     > > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>>
>     > >http://python.cn/mailman/listinfo/python-chinese
>     <http://python.cn/mailman/listinfo/python-chinese>
>     > >
>     > >
>     >
>     >
>     >
>     >
>     >
>     > --
>     > Qiangning Hong
>     > Get Firefox!
>     > <
>     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
>     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>
>
>
>
>
>
> -- 
> Qiangning Hong
> Get Firefox!
> <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: william.vcf
Type: text/x-vcard
Size: 154 bytes
Desc: not available
Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050501/995d2aef/william.vcf

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年05月01日 星期日 14:05

Qiangning Hong hongqn at gmail.com
Sun May 1 14:05:14 HKT 2005

因为table[0]、table[1]、table[2]都指向同一个list对象啊。

On 5/1/05, William Wu <william at sinowish.com> wrote:
> 
> 但是为什么当 table[1][1]=2 的时候 Table 却成为
> [[1, 2, 1], [1, 2, 1], [1, 2, 1]] 了呢?
> 
> 匪夷所思
> 
> Qiangning Hong wrote:
> 
> > [x] * 3 的意思是创建一个包含三个元素的list,其中每个元素都是x,也就是
> > 说这三个元素绑定的是同一个对象。
> >
> > table = [[1]*3]*3 等价于:
> > a = [1, 1, 1]
> > table = [a, a, a]
> >
> >
> > On 5/1/05, *William Wu* <william at sinowish.com
> > william at sinowish.com>> wrote:
> >
> > 的确,和解呢?
> >
> > Qiangning Hong wrote:
> >
> > > 这个构造出来的不是三维数组,修改其中一个元素就会导致其他元素发生
> > 变化。
> > >
> > > 例如:
> > >
> > > .>>> x = [[[1]*3]*3]*3
> > > .>>> x
> > > [[[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1,
> > 1, 1]],
> > > [[1, 1, 1], [1, 1, 1], [1, 1, 1]]]
> > > .>>> x[1][1][1] = 2
> > > .>>> x
> > > [[[1, 2, 1], [1, 2, 1], [1, 2, 1]], [[1, 2, 1], [1, 2, 1], [1,
> > 2, 1]],
> > > [[1, 2, 1], [1, 2, 1], [1, 2, 1]]]
> > >
> > >
> > >
> > > On 5/1/05, *William Wu* <william at sinowish.com
> > william at sinowish.com>
> > > william at sinowish.com william at sinowish.com>>> wrote:
> > >
> > > [[[1]*12]*12]*12
> > >
> > > Qiangning Hong wrote:
> > >
> > > > On 5/1/05, *Qiangning Hong* <hongqn at gmail.com
> > hongqn at gmail.com>
> > > hongqn at gmail.com hongqn at gmail.com>>
> > > > hongqn at gmail.com hongqn at gmail.com>
> > hongqn at gmail.com hongqn at gmail.com>>>> wrote:
> > > >
> > > > On 5/1/05, *jawbreaker* < jawbreaker at 163.com
> > jawbreaker at 163.com>
> > > jawbreaker at 163.com jawbreaker at 163.com>>
> > > > jawbreaker at 163.com jawbreaker at 163.com>
> > jawbreaker at 163.com jawbreaker at 163.com>>>> wrote:
> > > >
> > > > 在C中,我们会这样定义和初始化这样一个三维数组:
> > > > int Table[12][12][12];
> > > > for(i=0;i<12;i++)
> > > > for(j=0;j<12;j++)
> > > > for(k=0;k<12;k++)
> > > > Table[i][j][k]=1;
> > > >
> > > >
> > > > Table = [[[[1] * 12] for x in range(12)] for x in range(12)]
> > > >
> > > >
> > > > 不好意思,写错了,应该是:
> > > > Table = [ [ [1] * 12 for x in range(12) ] for x in range(12) ]
> > > >
> > > > --
> > > > Qiangning Hong
> > > > Get Firefox!
> > > > <
> > > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> > > <
> > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
> > > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
> > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>
> > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
> > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>>>>
> > > >
> > >
> > 
> >------------------------------------------------------------------------
> >
> > > >
> > > >_______________________________________________
> > > >python-chinese list
> > > > python-chinese at lists.python.cn
> > python-chinese at lists.python.cn>
> > > python-chinese at lists.python.cn
> > python-chinese at lists.python.cn>>
> > > >http://python.cn/mailman/listinfo/python-chinese
> > <http://python.cn/mailman/listinfo/python-chinese>
> > > >
> > > >
> > >
> > >
> > >
> > >
> > >
> > > --
> > > Qiangning Hong
> > > Get Firefox!
> > > <
> > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> > > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>
> >
> >
> >
> >
> >
> > --
> > Qiangning Hong
> > Get Firefox!
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
> 
> 
> 


-- 
Qiangning Hong
Get Firefox! <
http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050501/e069dd33/attachment.html

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年05月01日 星期日 14:10

William Wu william at sinowish.com
Sun May 1 14:10:01 HKT 2005

呵呵,知道了

Qiangning Hong wrote:

> 因为table[0]、table[1]、table[2]都指向同一个list对象啊。
>
> On 5/1/05, *William Wu* <william at sinowish.com
> william at sinowish.com>> wrote:
>
>     但是为什么当 table[1][1]=2 的时候 Table 却成为
>     [[1, 2, 1], [1, 2, 1], [1, 2, 1]] 了呢?
>
>     匪夷所思
>
>     Qiangning Hong wrote:
>
>     > [x] * 3 的意思是创建一个包含三个元素的list,其中每个元素都是x,
>     也就是
>     > 说这三个元素绑定的是同一个对象。
>     >
>     > table = [[1]*3]*3 等价于:
>     > a = [1, 1, 1]
>     > table = [a, a, a]
>     >
>     >
>     > On 5/1/05, *William Wu* <william at sinowish.com
>     william at sinowish.com>
>     > william at sinowish.com william at sinowish.com>>> wrote:
>     >
>     > 的确,和解呢?
>     >
>     > Qiangning Hong wrote:
>     >
>     > > 这个构造出来的不是三维数组,修改其中一个元素就会导致其他元素发生
>     > 变化。
>     > >
>     > > 例如:
>     > >
>     > > .>>> x = [[[1]*3]*3]*3
>     > > .>>> x
>     > > [[[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1,
>     > 1, 1]],
>     > > [[1, 1, 1], [1, 1, 1], [1, 1, 1]]]
>     > > .>>> x[1][1][1] = 2
>     > > .>>> x
>     > > [[[1, 2, 1], [1, 2, 1], [1, 2, 1]], [[1, 2, 1], [1, 2, 1], [1,
>     > 2, 1]],
>     > > [[1, 2, 1], [1, 2, 1], [1, 2, 1]]]
>     > >
>     > >
>     > >
>     > > On 5/1/05, *William Wu* <william at sinowish.com
>     william at sinowish.com>
>     > william at sinowish.com william at sinowish.com>>
>     > > william at sinowish.com william at sinowish.com>
>     william at sinowish.com william at sinowish.com>>>> wrote:
>     > >
>     > > [[[1]*12]*12]*12
>     > >
>     > > Qiangning Hong wrote:
>     > >
>     > > > On 5/1/05, *Qiangning Hong* <hongqn at gmail.com
>     hongqn at gmail.com>
>     > hongqn at gmail.com hongqn at gmail.com>>
>     > > hongqn at gmail.com hongqn at gmail.com>
>     hongqn at gmail.com hongqn at gmail.com>>>
>     > > > hongqn at gmail.com hongqn at gmail.com>
>     hongqn at gmail.com hongqn at gmail.com>>
>     > hongqn at gmail.com hongqn at gmail.com> >     hongqn at gmail.com hongqn at gmail.com>>>>> wrote:
>     > > >
>     > > > On 5/1/05, *jawbreaker* < jawbreaker at 163.com
>     jawbreaker at 163.com>
>     > jawbreaker at 163.com jawbreaker at 163.com>>
>     > > jawbreaker at 163.com jawbreaker at 163.com>
>     jawbreaker at 163.com jawbreaker at 163.com>>>
>     > > > jawbreaker at 163.com jawbreaker at 163.com>
>     jawbreaker at 163.com jawbreaker at 163.com>>
>     > jawbreaker at 163.com jawbreaker at 163.com> >     jawbreaker at 163.com jawbreaker at 163.com>>>>> wrote:
>     > > >
>     > > > 在C中,我们会这样定义和初始化这样一个三维数组:
>     > > > int Table[12][12][12];
>     > > > for(i=0;i<12;i++)
>     > > > for(j=0;j<12;j++)
>     > > > for(k=0;k<12;k++)
>     > > > Table[i][j][k]=1;
>     > > >
>     > > >
>     > > > Table = [[[[1] * 12] for x in range(12)] for x in range(12)]
>     > > >
>     > > >
>     > > > 不好意思,写错了,应该是:
>     > > > Table = [ [ [1] * 12 for x in range(12) ] for x in range(12) ]
>     > > >
>     > > > --
>     > > > Qiangning Hong
>     > > > Get Firefox!
>     > > > <
>     > >
>     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
>     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
>     > > <
>     > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
>     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>
>     > > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
>     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>
>     > < http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
>     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>>
>     > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
>     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>
>     > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
>     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>>>>>
>     > > >
>     > >
>     >
>     >------------------------------------------------------------------------
>     >
>     > > >
>     > > >_______________________________________________
>     > > >python-chinese list
>     > > > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>>
>     > > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>
>     > python-chinese at lists.python.cn
>     python-chinese at lists.python.cn>>>
>     > > > http://python.cn/mailman/listinfo/python-chinese
>     > <http://python.cn/mailman/listinfo/python-chinese>
>     > > >
>     > > >
>     > >
>     > >
>     > >
>     > >
>     > >
>     > > --
>     > > Qiangning Hong
>     > > Get Firefox!
>     > > <
>     > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
>     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
>     > >
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
>     > <
>     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>>
>     >
>     >
>     >
>     >
>     >
>     > --
>     > Qiangning Hong
>     > Get Firefox!
>     > <
>     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
>     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
>     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>
>
>
>
>
>
> -- 
> Qiangning Hong
> Get Firefox!
> <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: william.vcf
Type: text/x-vcard
Size: 154 bytes
Desc: not available
Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20050501/8672e479/william-0001.vcf

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年05月08日 星期日 21:36

梅劲松  stephen.cn at gmail.com
Sun May 8 21:36:54 HKT 2005

我倒认为用
{1:{1:1}}
{2:{1:1}}
...
{3:{2:1}}
...
这样的方式存储更容易使用.

在05-5-1,William Wu<william at sinowish.com> 写道:
> 呵呵,知道了
> 
> Qiangning Hong wrote:
> 
> > 因为table[0]、table[1]、table[2]都指向同一个list对象啊。
> >
> > On 5/1/05, *William Wu* <william at sinowish.com
> > william at sinowish.com>> wrote:
> >
> >     但是为什么当 table[1][1]=2 的时候 Table 却成为
> >     [[1, 2, 1], [1, 2, 1], [1, 2, 1]] 了呢?
> >
> >     匪夷所思
> >
> >     Qiangning Hong wrote:
> >
> >     > [x] * 3 的意思是创建一个包含三个元素的list,其中每个元素都是x,
> >     也就是
> >     > 说这三个元素绑定的是同一个对象。
> >     >
> >     > table = [[1]*3]*3 等价于:
> >     > a = [1, 1, 1]
> >     > table = [a, a, a]
> >     >
> >     >
> >     > On 5/1/05, *William Wu* <william at sinowish.com
> >     william at sinowish.com>
> >     > william at sinowish.com william at sinowish.com>>> wrote:
> >     >
> >     > 的确,和解呢?
> >     >
> >     > Qiangning Hong wrote:
> >     >
> >     > > 这个构造出来的不是三维数组,修改其中一个元素就会导致其他元素发生
> >     > 变化。
> >     > >
> >     > > 例如:
> >     > >
> >     > > .>>> x = [[[1]*3]*3]*3
> >     > > .>>> x
> >     > > [[[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [1,
> >     > 1, 1]],
> >     > > [[1, 1, 1], [1, 1, 1], [1, 1, 1]]]
> >     > > .>>> x[1][1][1] = 2
> >     > > .>>> x
> >     > > [[[1, 2, 1], [1, 2, 1], [1, 2, 1]], [[1, 2, 1], [1, 2, 1], [1,
> >     > 2, 1]],
> >     > > [[1, 2, 1], [1, 2, 1], [1, 2, 1]]]
> >     > >
> >     > >
> >     > >
> >     > > On 5/1/05, *William Wu* <william at sinowish.com
> >     william at sinowish.com>
> >     > william at sinowish.com william at sinowish.com>>
> >     > > william at sinowish.com william at sinowish.com>
> >     william at sinowish.com william at sinowish.com>>>> wrote:
> >     > >
> >     > > [[[1]*12]*12]*12
> >     > >
> >     > > Qiangning Hong wrote:
> >     > >
> >     > > > On 5/1/05, *Qiangning Hong* <hongqn at gmail.com
> >     hongqn at gmail.com>
> >     > hongqn at gmail.com hongqn at gmail.com>>
> >     > > hongqn at gmail.com hongqn at gmail.com>
> >     hongqn at gmail.com hongqn at gmail.com>>>
> >     > > > hongqn at gmail.com hongqn at gmail.com>
> >     hongqn at gmail.com hongqn at gmail.com>>
> >     > hongqn at gmail.com hongqn at gmail.com> > >     hongqn at gmail.com hongqn at gmail.com>>>>> wrote:
> >     > > >
> >     > > > On 5/1/05, *jawbreaker* < jawbreaker at 163.com
> >     jawbreaker at 163.com>
> >     > jawbreaker at 163.com jawbreaker at 163.com>>
> >     > > jawbreaker at 163.com jawbreaker at 163.com>
> >     jawbreaker at 163.com jawbreaker at 163.com>>>
> >     > > > jawbreaker at 163.com jawbreaker at 163.com>
> >     jawbreaker at 163.com jawbreaker at 163.com>>
> >     > jawbreaker at 163.com jawbreaker at 163.com> > >     jawbreaker at 163.com jawbreaker at 163.com>>>>> wrote:
> >     > > >
> >     > > > 在C中,我们会这样定义和初始化这样一个三维数组:
> >     > > > int Table[12][12][12];
> >     > > > for(i=0;i<12;i++)
> >     > > > for(j=0;j<12;j++)
> >     > > > for(k=0;k<12;k++)
> >     > > > Table[i][j][k]=1;
> >     > > >
> >     > > >
> >     > > > Table = [[[[1] * 12] for x in range(12)] for x in range(12)]
> >     > > >
> >     > > >
> >     > > > 不好意思,写错了,应该是:
> >     > > > Table = [ [ [1] * 12 for x in range(12) ] for x in range(12) ]
> >     > > >
> >     > > > --
> >     > > > Qiangning Hong
> >     > > > Get Firefox!
> >     > > > <
> >     > >
> >     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> >     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
> >     > > <
> >     > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> >     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>
> >     > > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>
> >     > < http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>>
> >     > > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>
> >     > <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id;=67907&t;=1>>>>>
> >     > > >
> >     > >
> >     >
> >     >------------------------------------------------------------------------
> >     >
> >     > > >
> >     > > >_______________________________________________
> >     > > >python-chinese list
> >     > > > python-chinese at lists.python.cn
> >     python-chinese at lists.python.cn>
> >     > python-chinese at lists.python.cn
> >     python-chinese at lists.python.cn>>
> >     > > python-chinese at lists.python.cn
> >     python-chinese at lists.python.cn>
> >     > python-chinese at lists.python.cn
> >     python-chinese at lists.python.cn>>>
> >     > > > http://python.cn/mailman/listinfo/python-chinese
> >     > <http://python.cn/mailman/listinfo/python-chinese>
> >     > > >
> >     > > >
> >     > >
> >     > >
> >     > >
> >     > >
> >     > >
> >     > > --
> >     > > Qiangning Hong
> >     > > Get Firefox!
> >     > > <
> >     > http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> >     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
> >     > >
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> >     > <
> >     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>>
> >     >
> >     >
> >     >
> >     >
> >     >
> >     > --
> >     > Qiangning Hong
> >     > Get Firefox!
> >     > <
> >     http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>
> >     > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> >     <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>>
> >
> >
> >
> >
> >
> > --
> > Qiangning Hong
> > Get Firefox!
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1
> > <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>>
> 
> 
> _______________________________________________
> python-chinese list
> python-chinese at lists.python.cn
> http://python.cn/mailman/listinfo/python-chinese
> 
> 
> 
> 


-- 
梅劲松

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年05月09日 星期一 19:49

song shulin shulin.song at gmail.com
Mon May 9 19:49:58 HKT 2005

为什么大家不用numarray定义数组呢?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050509/9fed1337/attachment.htm

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号