Created
May 6, 2023 00:47
-
-
Save martin-martin/1008796754d42ec2487874529304803f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def create_deck(): | |
RANKS = '2 3 4 5 6 7 8 9 10 J Q K A'.split() | |
SUITS = '♣ ♢ ♡ ♠'.split() | |
return np.array([r + s for s in SUITS for r in RANKS]) | |
print(create_deck()) | |
# ['2♣' '3♣' '4♣' '5♣' '6♣' '7♣' '8♣' '9♣' '10♣' 'J♣' 'Q♣' 'K♣' 'A♣' '2♢' | |
# '3♢' '4♢' '5♢' '6♢' '7♢' '8♢' '9♢' '10♢' 'J♢' 'Q♢' 'K♢' 'A♢' '2♡' '3♡' | |
# '4♡' '5♡' '6♡' '7♡' '8♡' '9♡' '10♡' 'J♡' 'Q♡' 'K♡' 'A♡' '2♠' '3♠' '4♠' | |
# '5♠' '6♠' '7♠' '8♠' '9♠' '10♠' 'J♠' 'Q♠' 'K♠' 'A♠'] |
Or, if this is too overwhelming, you could make a selection of cards first. For example, the Austrian card game called Schnapsen is played with only 10 J Q K A:
>>> schnapsen_deck = stacked_deck[:,-5:]
>>> schnapsen_deck
array([['10♣', 'J♣', 'Q♣', 'K♣', 'A♣'],
['10♢', 'J♢', 'Q♢', 'K♢', 'A♢'],
['10♡', 'J♡', 'Q♡', 'K♡', 'A♡'],
['10♠', 'J♠', 'Q♠', 'K♠', 'A♠']], dtype='<U3')
With this deck, you'd (nearly) be back to the amount of elements that you're using in your examples, but it adds a bit of real-world meaning to it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also gives you a nice opportunity to show what
.permutation()
,.shuffle()
, and.permuted()
do:For example. Then with
.shuffle()
you can show that it works in-place. Also makes sense to discuss theaxis
parameter on it, if you want to highlight the differences and similarities.