467,092 Members | 1,260 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,092 developers. It's quick & easy.

In line 7 - 'list' object has no attribute 'ndim'

2Bits
import numpy as np
from numpy import arange
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.pyplot as plt

def map2(fn, A, B):
"""Map fn to corresponding elements of 2D arrays A and B."""
return[list(map(fn, Arow, Brow)) for (Arow, Brow) in zip(A, B)]

def score(A, B):
"""Compute the outcome of the race for player A, given A and B to be speeds of the cars."""
assert 10 <= A <= 100 and 10 <= B <= 100 # you can't get too slow or too fast
trackA = 100 - B
trackB = 100 - A
tA = trackA/A
tB = trackB/B
return tB - tA

## Graph the space of possible scores for A

speeds = arange(10, 101)
A, B = np.meshgrid(speeds, speeds)
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.set_xlabel('Speed of A')
ax.set_ylabel('Speed of B')
ax.set_zlabel('Race Score for A')
ax.plot_surface(A, B, map2(score, A, B));
fig.show()

## Maximum score for A
print("Max score for A:", max([score(A, B), A, B] for A in speeds for B in speeds))

## If player B gets to respond with a speed choice, with full knowledge of A's choice, what
## speed should A choose to maximize the score?
print("Max score for A if B responds:",
max(min([score(A, B), A, B] for B in speeds) for A in speeds))

## What if B chooses a speed first, and then A responds?
print("Max score for A if A responds:",
min(max([score(A, B), A, B] for A in speeds) for B in speeds))
1 Week Ago #1

✓ answered by JupyterPS1

It's not in line 7 - BUT when you run the code you get the following message:

-> 1555 if Z.ndim != 2:
1556 raise ValueError("Argument Z must be 2-dimensional.")
1557 if np.any(np.isnan(Z)):

  • viewed: 1506
Share:
1 Reply
2Bits
It's not in line 7 - BUT when you run the code you get the following message:

-> 1555 if Z.ndim != 2:
1556 raise ValueError("Argument Z must be 2-dimensional.")
1557 if np.any(np.isnan(Z)):
1 Week Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Muhammad Ahsin Saleem | last post: by
2 posts views Thread by jeremito | last post: by
2 posts views Thread by Steve Potter | last post: by
5 posts views Thread by =?Utf-8?B?RWl0YW4=?= | last post: by
6 posts views Thread by kdt | last post: by
3 posts views Thread by Gandalf | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.