Hi all,
I was able to run the whole C1_W3_Lab_3_linear_transformations notebook within the Coursera platform. However, when I downloaded it and tried running it locally, I kept getting this error after reaching the 2nd cell of the section 4.1 - Example 1: Horizontal Scaling (Dilation)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [6], in <cell line: 41>()
38 plt.gca().set_aspect("equal")
39 plt.show()
---> 41 plot_transformation(T_hscaling, e1, e2)
Input In [6], in plot_transformation(T, e1, e2)
13 plt.axis([-5, 5, -5, 5])
14 plt.quiver([0, 0],[0, 0], [e1[0], e2[0]], [e1[1], e2[1]], color=color_original, angles='xy', scale_units='xy', scale=1)
---> 15 plt.plot([0, e2[0], e1[0], e1[0]],
16 [0, e2[1], e2[1], e1[1]],
17 color=color_original)
18 e1_sgn = 0.4 * np.array([[1] if i==0 else [i] for i in np.sign(e1)])
19 ax.text(e1[0]-0.2+e1_sgn[0], e1[1]-0.2+e1_sgn[1], f'$e_1$', fontsize=14, color=color_original)
File ~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/pyplot.py:2757, in plot(scalex, scaley, data, *args, **kwargs)
2755 @_copy_docstring_and_deprecators(Axes.plot)
2756 def plot(*args, scalex=True, scaley=True, data=None, **kwargs):
-> 2757 return gca().plot(
2758 *args, scalex=scalex, scaley=scaley,
2759 **({"data": data} if data is not None else {}), **kwargs)
File ~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_axes.py:1632, in Axes.plot(self, scalex, scaley, data, *args, **kwargs)
1390 """
1391 Plot y versus x as lines and/or markers.
1392
(...)
1629 (``'green'``) or hex strings (``'#008000'``).
1630 """
1631 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
-> 1632 lines = [*self._get_lines(*args, data=data, **kwargs)]
1633 for line in lines:
1634 self.add_line(line)
File ~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py:312, in _process_plot_var_args.__call__(self, data, *args, **kwargs)
310 this += args[0],
311 args = args[1:]
--> 312 yield from self._plot_args(this, kwargs)
File ~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_base.py:487, in _process_plot_var_args._plot_args(self, tup, kwargs, return_kwargs)
484 kw[prop_name] = val
486 if len(xy) == 2:
--> 487 x = _check_1d(xy[0])
488 y = _check_1d(xy[1])
489 else:
File ~/opt/anaconda3/lib/python3.9/site-packages/matplotlib/cbook/__init__.py:1304, in _check_1d(x)
1302 """Convert scalars to 1D arrays; pass-through arrays as is."""
1303 if not hasattr(x, 'shape') or len(x.shape) < 1:
-> 1304 return np.atleast_1d(x)
1305 else:
1306 try:
1307 # work around
1308 # https://github.com/pandas-dev/pandas/issues/27775 which
(...)
1319 # This code should correctly identify and coerce to a
1320 # numpy array all pandas versions.
File ~/opt/anaconda3/lib/python3.9/site-packages/numpy/core/shape_base.py:65, in atleast_1d(*arys)
63 res = []
64 for ary in arys:
---> 65 ary = asanyarray(ary)
66 if ary.ndim == 0:
67 result = ary.reshape(1)
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (4,) + inhomogeneous part.
This seems to arise in line plot_transformation(T_hscaling, e1, e2), which I’m not sure why. The whole notebook works well in Coursera; should it be a problem with my local environment?
Please advise. Thank you all so much in advance!
Ginny