473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

2 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))
Jan 7 '21 #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)):

1 4339
JupyterPS1
2 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)):
Jan 7 '21 #2

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

Similar topics

4
by: python newbie | last post by:
Is there anything that would get in the way of me being able to reference an object attribute, from within a list. I have: # one class here class BackupSet: fileGroupList = # ...
3
by: moondaddy | last post by:
I'm wanting to create a bindable list object made up of a list of business classes. I'm writing this in a vb.net 1.1 winforms app and am using a code example by Rocky Lhotka for reference...
3
by: Muhammad Ahsin Saleem | last post by:
Hi I want to make a multi Line List Box. This list box will have multiple lines for one item and this list box have all other functions like the single line list box. Can any body help me its...
2
by: jeremito | last post by:
I have created a class that inherits from the list object. I want to override the append function to allow my class to append several copies at the same time with one function call. I want to do...
2
by: Steve Potter | last post by:
I am trying to find some method of attaching a Listbox object to a list object so as the contents of the list are changed the contents of the Listbox will be updated to match. I have found a few...
5
by: =?Utf-8?B?RWl0YW4=?= | last post by:
Hello, I am writing an application in c#. I have a List object that I would like to bind it to a DataGridView control. Can I do that, and if so how? If I can not do that, is there any other...
6
by: kdt | last post by:
Hi I have a function for calculating the standard deviation of a list. I was wanting to create this as an object and inherit from pythons list object. I'm pretty new to the whole OOP concept,...
3
by: Gandalf | last post by:
my manual contain chapter about lists with python. when i try to copy paste : li = (1) it i get this errore: "TypeError: 'list' object is not callable"
3
by: zendas | last post by:
Hi all, I m fairly new to programming so I am sorry if this is a simple answer. I am writing a program that creates a bar graph using a list of numbers. I am having problems multiplying the list...
0
by: NightStar | last post by:
When i run my file, no problem, when I do the command, i get an error code that i dont know how to resovle, I have no list created. Here is the error code : `line 13, in on_message if...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.