Skip to main content
edited tags
Link
GuedesBF
  • 10k
  • 5
  • 23
  • 42
Source Link

I get the error 'ValueError: NumPy boolean array indexing assignment cannot assign 100 input values to the 90 output values where the mask is true'

This is my code, and I get the following error:

ValueError: NumPy boolean array indexing assignment cannot assign 100 input values to the 90 output values where the mask is true. The error is on the line assigning a value for V.

What am I doing wrong?

from pylab import * 
import numpy as np
from math import *
r = np.linspace(0, 10, 100)

V = np.piecewise(r, [r < 1, r > 1 ], [1, (r/2)*(3 - (r**2))])

#Graph of V r / k q vs. r/R for unitless quantities

figure()
plot(r, V)
xlabel('r / R') 
ylabel('V r / k q') 
title('Behavior of V(r) vs r')

ax = plt.gca()

ax.set_xticks([1])
  
ax.set_xticklabels(['R'])

plt.tick_params(left = False, right = False , labelleft = False)

grid()

show()