Skip to content Skip to sidebar Skip to footer

Valueerror When Using If Commands In Function

I'm creating some functions that I can call use keywords to call out specific functions, import scipy.integrate as integrate import numpy as np def HubbleParam(a, model = 'None'):

Solution 1:

In EmitterDistance() your first argument to integrate.quad() should a function. But it is an array, instead.

Solution 2:

This kind of error results when you use an array in a context that expects a scalar value. It is testing a != -Inf in an if expression. a and b here are the boundary points of the integration. They should be scalars, not arrays. But you are calling quad with:

 quad(integrand, a, a)

a here is a = 1./(1.+z), and z is the array produced by linspace.

integrand also looks problematic. It is array derived from a. It should, instead, be a function. Something that takes a scalar and returns a value. HubbleParam might work, or a lambda or function def using it.

Post a Comment for "Valueerror When Using If Commands In Function"