Nashpy

0.0.43 · active · verified Mon Apr 13

Nashpy is a Python library providing algorithms for computing Nash equilibria and analyzing 2-player games, including matrix games and repeated games. It is built on top of NumPy and SciPy for efficient numerical computation. Currently at version 0.0.43, the library maintains a frequent release cadence, typically with minor updates and bug fixes.

Warnings

Install

Imports

Quickstart

This example demonstrates how to define a 2-player, 2-strategy game using NumPy arrays for payoff matrices and find its Nash equilibria using the `support_enumeration` algorithm.

import nashpy as nash
import numpy as np

# Define payoff matrices for player 1 (A) and player 2 (B)
A = np.array([[3, 0], [5, 1]])
B = np.array([[3, 5], [0, 1]])

# Create a Nash game object
game = nash.Game(A, B)

# Compute Nash equilibria using support enumeration
equilibria = game.support_enumeration()

# Print the equilibria (mixed strategies for each player)
print("Nash Equilibria:")
for eq in equilibria:
    print(eq)

view raw JSON →