orlandpm / math-for-programmers Goto Github PK
View Code? Open in Web Editor NEWSource code for the book, Math for Programmers
Source code for the book, Math for Programmers
On page 47 of the book, mini-project 2.19, solution says the coordinates are:
(2,4), (4,2), (2,4), and (4, -2)
Should be:
(-2,4), (-4,2), (2,4), and (4, -2)
Not sure if this is the right place to submit or not. Is there a public errata anywhere?
When running the following code from ch03_walkthrough.ipynb
draw3d( Points3D((2,2,2),(1,-2,-2)), Arrow3D((2,2,2)), Arrow3D((1,-2,-2)), Segment3D((2,2,2), (1,-2,-2)) )
The following exception is thrown:
TypeError Traceback (most recent call last)
/media/data/asim/devel/python/math/Math-for-Programmers/Chapter 03/ch03_walkthrough.ipynb Cell 6 line 1
----> 1 draw3d(
2 Points3D((2,2,2),(1,-2,-2)),
3 Arrow3D((2,2,2)),
4 Arrow3D((1,-2,-2)),
5 Segment3D((2,2,2), (1,-2,-2))
6 )
File /media/data/asim/devel/python/math/Math-for-Programmers/Chapter 03/draw3d.py:84, in draw3d(origin, axes, width, save_as, azim, elev, xlim, ylim, zlim, xticks, yticks, zticks, depthshade, *objects)
81 ax = fig.add_subplot(111, projection='3d')
82 ax.view_init(elev=elev,azim=azim)
---> 84 all_vectors = list(extract_vectors_3D(objects))
85 if origin:
86 all_vectors.append((0,0,0))
File /media/data/asim/devel/python/math/Math-for-Programmers/Chapter 03/draw3d.py:76, in extract_vectors_3D(objects)
74 yield object.vector
75 else:
---> 76 raise TypeError("Unrecognized object: {}".format(object))
TypeError: Unrecognized object: <draw3d.Points3D object at 0x7f83cdf68a00>
I'am having this error while trying to import vector_drowing
When I run this cell:
sound = pygame.sndarray.make_sound(arr)
sound.play()
I get this error:
ValueError Traceback (most recent call last)
<ipython-input-18-f6cf0bf38cc3> in <module>
----> 1 sound = pygame.sndarray.make_sound(arr)
2 sound.play()
~/anaconda3/envs/intern/lib/python3.7/site-packages/pygame/sndarray.py in make_sound(array)
92 global numpysnd
93 try:
---> 94 return numpysnd.make_sound(array)
95 except AttributeError:
96 import pygame._numpysndarray as numpysnd
~/anaconda3/envs/intern/lib/python3.7/site-packages/pygame/_numpysndarray.py in make_sound(array)
72 """
73
---> 74 return mixer.Sound(array=array)
ValueError: Unsupported integer size 8
I am using Python 3.7.9 on Ubuntu 20.04 LTS.
Seems like mlp._predict
may be deprecated(?), as the following error is raised when running 16.4.3 (scikit-learn v0.24.2):
AttributeError Traceback (most recent call last)
in
----> 1 mlp._predict(x)[0]AttributeError: 'MLPClassifier' object has no attribute '_predict'
From scikit-learn, seems like the method to use is predict_proba(x).
So, mlp.predict_proba(x)[0]
seems to work correctly.
Hi. In chapter 5 when doing exercise on infer_matrix (exercise 5.1) I didnt receive same basis vectors, when I inferred matrix and when I rotated standard basis manually. The problem is, that I think you are missing the minus sign in your rotate_by functions. See picture.
Here is the testing code I did with original functions for rotation, with unchanged sign. And result below shows difference.
%load_ext autoreload
%autoreload 2
%matplotlib qt
import sys
sys.path.append(os.getcwd())
from draw3d import *
from draw2d import *
import math
def length(v):
return sqrt(sum([coord ** 2 for coord in v]))
def to_polar(vector):
x, y = vector[0], vector[1]
angle = math.atan2(y,x)
return (length(vector), angle)
def to_cartesian(polar_vector):
length, angle = polar_vector[0], polar_vector[1]
return (length*math.cos(angle), length*math.sin(angle))
def rotate2d(angle, vector):
l,a = to_polar(vector)
return to_cartesian((l, a+angle))
def rotate_y(angle,vector):
x,y,z = vector
new_x, new_z = rotate2d(angle, (x,z))
return new_x, y, new_z
def rotate_y_by(angle):
def new_function(v):
return rotate_y(angle,v)
return new_function
rotate_y_by_90 = rotate_y_by(pi/2)
x = (1,0,0)
y = (0,1,0)
z = (0,0,1)
x_by_y_90 = rotate_y_by_90(x)
y_by_y_90 = rotate_y_by_90(y)
z_by_y_90 = rotate_y_by_90(z)
def infer_matrix(n, transformation):
def standard_basis_vector(i):
return tuple(1 if i==j else 0 for j in range(1,n+1))
standard_basis = [standard_basis_vector(i) for i in range(1,n+1)]
cols = [transformation(v) for v in standard_basis]
return tuple(zip(*cols))
infered_x = infer_matrix(3,rotate_y_by_90)[0]
infered_y = infer_matrix(3,rotate_y_by_90)[1]
infered_z = infer_matrix(3,rotate_y_by_90)[2]
draw3d(
Arrow3D(x, color=cnames['green']),
Arrow3D(y, color=cnames['blue']),
Arrow3D(z, color=cnames['purple']),
Arrow3D(infered_x, color=cnames['lime']),
Arrow3D(infered_y, color=cnames['aqua']),
Arrow3D(infered_z, color=cnames['magenta']),
)
# Manual
print("Manual")
print(x_by_y_90)
print(y_by_y_90)
print(z_by_y_90)
# Infered
print("Infered:")
print(infered_x)
print(infered_y)
print(infered_z)
And result:
Manual
(6.123233995736766e-17, 0, 1.0)
(0.0, 1, 0.0)
(-1.0, 0, 1.2246467991473532e-16)
Infered:
(6.123233995736766e-17, 0.0, -1.0)
(0, 1, 0)
(1.0, 0.0, 1.2246467991473532e-16)
After I change the sign, it all matches.
Also here is a source saying that when we do rotation by 90 degrees counterclockwise, we multiply one of the parts by -1, and swap:
https://limnu.com/sketch-easy-90-degree-rotate-vectors/
Is it correct? Thanks
Hi, there is a missing return in function on page 320. (Took me some time to figure out).
Should be:
def get_flow_rate_function(v):
def flow_rate_function(t):
return instantaneous_flow_rate(v,t)
return flow_rate_function
It generates an error.
In section 9.3.1 "Carrying out Euler's method by hand" an initial table is provided and a walk through for completing the first 3 rows begins. There appears to be a contradiction in the explained vector value for row 2, where we calculate this value for the vector column as (1, 0.4) but the table is completed as an example with the value (1,0) for v(2).
Either the table is incorrect and should appear as
t | s(t) | v(t) | a(t) |
---|---|---|---|
0 | (0,0) | (1,0) | (0, 0.2) |
2 | (2,0) | (1, 0.4) | (0, 0.2) |
4 | (0, 0.2) | ||
6 | (0, 0.2) | ||
8 | (0, 0.2) |
Or the table is correct but the discrepancy for the v(2) value should be explained.
It gets a warning.
c = ax.pcolormesh(X, Y, z, cmap='plasma')
should be
c = ax.pcolormesh(X, Y, z, cmap='plasma', shading='auto')
Thanks,
I am unable to run through the examples in the Jupyter notebook file for chapter 3.
matplotlib 3.5.0
matplotlib-inline 0.1.3
Showing the top of the callstack
~/projects/math/venv/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py in draw(self, renderer)
445 for axis in self._get_axis_list()) + 1
446 collection_zorder = patch_zorder = zorder_offset
--> 447 for artist in sorted(collections_and_patches,
448 key=do_3d_projection,
449 reverse=True):
~/projects/math/venv/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py in do_3d_projection(artist)
434 "do_3d_projection() was deprecated in Matplotlib "
435 "%(since)s and will be removed %(removal)s.")
--> 436 return artist.do_3d_projection(renderer)
437
438 collections_and_patches = (
AttributeError: 'FancyArrow3D' object has no attribute 'do_3d_projection'
Hi! There is no need to use "*" and unpack vectors in this place.
It have gotten an error.
arr = arr.astype(np.int16)
sound = pygame.sndarray.make_sound(arr)
sound.play()
In the directories which contains a notebook including a code like "plt.savefig('figures/1.01.svg')".
Regards,
Arrow3D((-1,0,1), (3,0,4) ,color=red) should be Arrow3D((3,0,4), (-1,0,1) ,color=red) ?
Thanks,
Hi. The solution to exercise C.1 in Appendix C sends the reader to check the draw_teapot_glrotatef.py
file. However, there is no such file.
At this time, there are multiple failures that can be encountered in the code base due to difference in dependency versions like matplotlib.
A requirements.txt file should be added in the project to list the dependencies and their versions compatible with the code base so users can easily run the examples and exercises.
when I try to import vector_drawing, I get an error. what am I doing wrong? thanks.
It seems like the notebooks should serve two purposes. 1. to provide code boilerplate code and be able to follow along and play with the code that has been created in the book. And 2, let the user do the exercises in the context of the existing boilerplate.
For some reason all of the exercises are already solved which takes away much of the advantage of using the notebook. Why aren't there two notebooks? One for following along with the book and solving exercises, and another for seeing the solutions to those exercises?
There is a hidden folder with a copy of the notebook but which have the same name except append the file name with "-checkpoint" for some unexplained reason.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.