1
$\begingroup$
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

observations = 1000
xs = np.random.uniform(low=-10, high=10, size=(observations,1))
zs = np.random.uniform(-10, 10, (observations,1))
inputs = np.column_stack((xs,zs))
noise = np.random.uniform(-1, 1, (observations,1))
targets = 2*xs - 3*zs + 5 + noise

targets = targets.reshape(observations,)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(xs, zs, targets)

# Set labels
ax.set_xlabel('xs')
ax.set_ylabel('zs')
ax.set_zlabel('Targets')

ax.view_init(azim=100)

plt.show()

targets = targets.reshape(observations,1)

I'm receiving the error for the above block of code:

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

---> ax.plot(xs, zs, targets)
$\endgroup$

2 Answers 2

1
$\begingroup$

Reshape the xs and zs variables as well as matplotlib no longer supports scalar input in (1,1,N) format. Reshape xs and zs input variables too along with target variable.

Add this 2 lines below the target reshaping variable it will work:

xs = xs.reshape(observations,)

zs = zs.reshape(observations,)

Note: Once done with plotting, remember to reshape all variables back to original scalar array form for optimization algorithm to work.

$\endgroup$
0
$\begingroup$

This is more of a programming question than a data science question and would therefore be better suited for the stackoverflow stackexchange page. However, the code you provided works perfectly fine for me, it gives me the following plot:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.