Demo entry 6736393

Oppgave 3b

   

Submitted by anonymous on Apr 26, 2018 at 16:37
Language: Python. Code size: 767 Bytes.

import numpy as np

persians = np.array([[1, 2, 2], [2, 2, 1], [2, 1, 2], [3, 1, 1], [1, 3, 1], [1, 1, 3]])
greeks = np.array([[1, 2, 2], [2, 2, 1], [2, 1, 2], [3, 1, 1], [1, 3, 1], [1, 1, 3]])

payoff = np.zeros((6,6))

for i in range(6):
    for j in range(6):

        greek_win = 0
        persian_win = 0

        for k in range(3):
            if ((greeks[j][k] - persians[i][k]) >= 0):
                greek_win += 1
            else:
                persian_win += 1

        value = greek_win - persian_win

        payoff[i][j] = value

print (payoff)

'''
[[ 3.  1.  1. -1.  1.  1.]
 [ 1.  3.  1.  1.  1. -1.]
 [ 1.  1.  3.  1. -1.  1.]
 [ 1.  1.  1.  3.  1.  1.]
 [ 1.  1.  1.  1.  3.  1.]
 [ 1.  1.  1.  1.  1.  3.]]
'''

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).