Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array representation of cube? #19

Open
PAK90 opened this issue Feb 19, 2017 · 2 comments
Open

Array representation of cube? #19

PAK90 opened this issue Feb 19, 2017 · 2 comments

Comments

@PAK90
Copy link

PAK90 commented Feb 19, 2017

I have need of an array representation of the cube, either as a flat array or an array of six arrays for each face. I haven't found anything existing to do this, so I've come up with my own hacky method, but this feels like something that should be part of the Cube class. Here's what I did:

def cubeAsArray(cube):
    faces = ["L", "R", "U", "D", "B", "F"]
    cubeArray = []
    for face in faces:
        face = cube.get_face(face)  # get face, iterate over all squares.
        for x in [0,1,2]:
            for y in [0,1,2]:
                cubeArray.append(str(face[x][y]))
    return cubeArray
@adrianliaw
Copy link
Owner

Hi @PAK90, although this kind of usage might be useful, I wouldn't consider this "should be" a part of the Cube class, because the design of Cube class is to use "cubie" as component of the cube instead of six faces. Though if you'd like to contribute to this project, you can add this function into pycuber/helpers.py and submit a pull request!

@jerpint
Copy link

jerpint commented Sep 5, 2017

Hi, here is a function I use to convert a cube to an ndarray, this is especially useful for ML applications

def cube2np(mycube):
    # transform cube object to np array
    # works around the weird data type used
    global faces
    global colors
    cube_np = np.zeros((6,3,3))
    for i,face in enumerate(faces):
        face_tmp = mycube.get_face(face)
        for j in range(3):
            for k in range(len(face_tmp[j])):
                caca = face_tmp[j][k]
                cube_np[i,j,k] = colors.index(str(caca))
    return cube_np

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants