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

About question 19 #191

Open
hacshyac opened this issue Dec 7, 2022 · 1 comment
Open

About question 19 #191

hacshyac opened this issue Dec 7, 2022 · 1 comment

Comments

@hacshyac
Copy link

hacshyac commented Dec 7, 2022

the alternative solution does not work for creating a checkerboard pattern.

# Alternative solution: Using reshaping
arr = np.ones(64,dtype=int)
arr[::2]=0
arr = arr.reshape((8,8))
print(arr)

this will be the output.
[[0 1 0 1 0 1 0 1]
[0 1 0 1 0 1 0 1]
[0 1 0 1 0 1 0 1]
[0 1 0 1 0 1 0 1]
[0 1 0 1 0 1 0 1]
[0 1 0 1 0 1 0 1]
[0 1 0 1 0 1 0 1]
[0 1 0 1 0 1 0 1]]

But what we want is

Z = np.zeros((8,8),dtype=int)
Z[1::2,::2] = 1
Z[::2,1::2] = 1
print(Z)

[[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]]

or

z = np.zeros((8, 8), int)
z[1::2, 1::2] = 1
z[::2, ::2] = 1
print(z)

[[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]
[1 0 1 0 1 0 1 0]
[0 1 0 1 0 1 0 1]]

@rougier
Copy link
Owner

rougier commented Dec 20, 2022

Thanks, it has been fixed recently.

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

2 participants