Nonliear magnetic problem with interplated BH curve

I want to solve a nonlinear magnetic problem.
I have defined a BH function using scipy.
I can not generate H from B with the error

ValueError: object arrays are not supported

from numpy import *
from scipy import interpolate

mu0 = 4*pi*1e-7 
H = linspace(0, 100e3, 1000)
B = 2 * tanh(H / 10e3) + mu0 * H
BH= interpolate.interp1d(B, H)
import ngsolve
print(ngsolve.__version__)
from ngsolve import *
from ngsolve.webgui import Draw

mesh = Mesh(unit_square.GenerateMesh(maxh=0.1))
fes = H1(mesh, order=2, dirichlet="left|right|bottom|top")
B = GridFunction(fes)
B.Set(x)
H = BH(B)

I have fitted the function.

Using the fitted function, I could obtain H.
Please let me know if there is a better way of doing this.

import ngsolve
print(ngsolve.__version__)
from ngsolve import *
from ngsolve.webgui import Draw

mesh = Mesh(unit_square.GenerateMesh(maxh=0.1))
fes = H1(mesh, order=2, dirichlet="left|right|bottom|top")
B = GridFunction(fes)
B.Set(2*x)
mu = GridFunction(fes)
mu.Set(160*sqrt(1-((B/2.5) + 0.17*(B/2.5)**4 + 0.24*(B/2.5)**8)**2))
H = GridFunction(fes)
H.Set(B/mu)
Draw(H)