Last answered:

05 Nov 2021

Posted on:

23 Jul 2021

2

Code not working on plotting 3d ax

ValueError                                Traceback (most recent call last)
<ipython-input-9-0900ac4f99cd> in <module>
     12 
     13 # Choose the axes.
---> 14 ax.plot(xs, zs, targets)
     15 
     16 # Set labels

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py in plot(self, xs, ys, zdir, *args, **kwargs)
   1467 
   1468         # Match length
-> 1469         zs = np.broadcast_to(zs, np.shape(xs))
   1470 
   1471         lines = super().plot(xs, ys, *args, **kwargs)

<__array_function__ internals> in broadcast_to(*args, **kwargs)

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/lib/stride_tricks.py in broadcast_to(array, shape, subok)
    178            [1, 2, 3]])
    179     """
--> 180     return _broadcast_to(array, shape, subok=subok, readonly=True)
    181 
    182 

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/numpy/lib/stride_tricks.py in _broadcast_to(array, shape, subok, readonly)
    121                          'negative')
    122     extras = []
--> 123     it = np.nditer(
    124         (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras,
    125         op_flags=['readonly'], itershape=shape, order='C')

ValueError: operands could not be broadcast together with remapped shapes [original->remapped]: (1000,) and requested shape (1000,1)

got this error on plot the training data , kindly assist

3 answers ( 0 marked as helpful)
Posted on:

28 Oct 2021

2

Getting the same error...Can someone please help with this?

Posted on:

04 Nov 2021

3

Using ax.scatter(xs, zs, targets)instead of plot works.

Posted on:

05 Nov 2021

18

You have two options here:

* One thing you can do is run in Google Colab, you will not have problems there.
* Another, you should add the following code after targets = targets.reshape(observations,) and before ax.plot(xs, zs, targets) to reshape xs to (observations,):
xs = xs.reshape(observations,) and add the following code after targets = targets.reshape(observations,1) to reshape it back: xs = xs.reshape(observations,1)

Submit an answer