By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

Rubik's cube translation

P: n/a
How do I get a Rubik's cube translation out of this:
>>a= numpy.array([[0,1,2],[3,4,5],[6,7,8]])
a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>a[:,0],a[:,1],a[:,2] #no good
(array([0, 3, 6]), array([1, 4, 7]), array([2, 5, 8]))
>>>
I need [[ 6, 3, 0 ], [ 7, 4, 1 ], [ 8, 5, 2 ]].
>>c= numpy.array([[ 6, 3, 0 ], [ 7, 4, 1 ], [ 8, 5, 2 ]])
c
array([[6, 3, 0],
[7, 4, 1],
[8, 5, 2]])
Mar 31 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Mon, Mar 31, 2008 at 12:24 PM, <ca********@gmail.comwrote:
How do I get a Rubik's cube translation out of this:
>>a= numpy.array([[0,1,2],[3,4,5],[6,7,8]])
>>a
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>a[:,0],a[:,1],a[:,2] #no good
(array([0, 3, 6]), array([1, 4, 7]), array([2, 5, 8]))
>>>

I need [[ 6, 3, 0 ], [ 7, 4, 1 ], [ 8, 5, 2 ]].
>>c= numpy.array([[ 6, 3, 0 ], [ 7, 4, 1 ], [ 8, 5, 2 ]])
>>c
array([[6, 3, 0],
[7, 4, 1],
[8, 5, 2]])
In [10]: numpy.rot90(a, 3)
Out[10]:
array([[6, 3, 0],
[7, 4, 1],
[8, 5, 2]])

Tim
--
http://mail.python.org/mailman/listinfo/python-list
Mar 31 '08 #2

P: n/a
On Mar 30, 9:48*pm, "Tim Leslie" <tim.les...@gmail.comwrote:
On Mon, Mar 31, 2008 at 12:24 PM, *<castiro...@gmail.comwrote:
How do I get a Rubik's cube translation out of this:
*>>a= numpy.array([[0,1,2],[3,4,5],[6,7,8]])
*>>a
*array([[0, 1, 2],
* * * *[3, 4, 5],
* * * *[6, 7, 8]])
*>>a[:,0],a[:,1],a[:,2] #no good
*(array([0, 3, 6]), array([1, 4, 7]), array([2, 5, 8]))
*I need [[ 6, 3, 0 ], [ 7, 4, 1 ], [ 8, 5, 2 ]].
*>>c= numpy.array([[ 6, 3, 0 ], [ 7, 4, 1 ], [ 8, 5, 2 ]])
*>>c
*array([[6, 3, 0],
* * * *[7, 4, 1],
* * * *[8, 5, 2]])

In [10]: numpy.rot90(a, 3)
Out[10]:
array([[6, 3, 0],
* * * *[7, 4, 1],
* * * *[8, 5, 2]])

Tim
What if this is connected:
>>D
array([[1, 2, 3],
[4, 5, 6],
[6, 7, 8]])
>>E
array([[6, 7, 8],
[0, 0, 0],
[0, 0, 0]])

-->
>>D
array([[1, 2, 3],
[4, 5, 6],
[6, 7, 8]])
>>E
array([[6, 7, 8],
[0, 0, 0],
[0, 0, 0]])
>>numpy.rot90( D )
array([[3, 6, 8],
[2, 5, 7],
[1, 4, 6]])
-->
>>E
array([[1, 4, 6],
[0, 0, 0],
[0, 0, 0]])

?
Mar 31 '08 #3

P: n/a
ca********@gmail.com wrote:
>
What if this is connected:
>>>D
array([[1, 2, 3],
[4, 5, 6],
[6, 7, 8]])
>>>E
array([[6, 7, 8],
[0, 0, 0],
[0, 0, 0]])

-->
>>>D
array([[1, 2, 3],
[4, 5, 6],
[6, 7, 8]])
>>>E
array([[6, 7, 8],
[0, 0, 0],
[0, 0, 0]])
>>>numpy.rot90( D )
array([[3, 6, 8],
[2, 5, 7],
[1, 4, 6]])
-->
>>>E
array([[1, 4, 6],
[0, 0, 0],
[0, 0, 0]])

?
If you don't want changes to D to affect E, then you need to disconnect
them when you create them. If you create D and E so that they contain
references to the same lists, then this kind of thing will happen.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Apr 1 '08 #4

P: n/a
On Apr 1, 1:00*am, Tim Roberts <t...@probo.comwrote:
castiro...@gmail.com wrote:
What if this is connected:
>>D
array([[1, 2, 3],
* * * [4, 5, 6],
* * * [6, 7, 8]])
>>E
array([[6, 7, 8],
* * * [0, 0, 0],
* * * [0, 0, 0]])
-->
>>D
array([[1, 2, 3],
* * * [4, 5, 6],
* * * [6, 7, 8]])
>>E
array([[6, 7, 8],
* * * [0, 0, 0],
* * * [0, 0, 0]])
>>numpy.rot90( D )
array([[3, 6, 8],
* * * [2, 5, 7],
* * * [1, 4, 6]])
-->
>>E
array([[1, 4, 6],
* * * [0, 0, 0],
* * * [0, 0, 0]])
?

If you don't want changes to D to affect E, then you need to disconnect
them when you create them. *If you create D and E so that they contain
references to the same lists, then this kind of thing will happen.
Basically, I need to change both D row 3 and E row 1 at the same time.
Apr 1 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.