Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

lineplot in plt

CHAPTER

                                                                                                           FOUR

                                                          FREQUENTLY ASKED QUESTIONS

A list of common questions.

4.1 How can I fit multi-dimensional data?

The fitting routines accept data arrays that are 1 dimensional and double precision. So you need to convert the data
and model (or the value returned by the objective function) to be one dimensional. A simple way to do this is to use
numpy’s numpy.ndarray.flatten(), for example:
def residual(params, x, data=None):
    ....
    resid = calculate_multidim_residual()
    return resid.flatten()

4.2 How can I fit multiple data sets?

As above, the fitting routines accept data arrays that are 1 dimensional and double precision. So you need to convert
the sets of data and models (or the value returned by the objective function) to be one dimensional. A simple way to
do this is to use numpy’s numpy.concatenate(). As an example, here is a residual function to simultaneously
fit two lines to two different arrays. As a bonus, the two lines share the ‘offset’ parameter:
      def fit_function(params, x=None, dat1=None, dat2=None): 
      		model1 = params[’offset’].value + x * params[’slope1’].value 
        	model2 = params[’offset’].value + x * params[’slope2’].value
           	resid1 = dat1 - model1 
            resid2 = dat2 - model2 
            return numpy.concatenate((resid1, resid2))

4.3 How can I fit complex data?

As with working with multidimensional data, you need to convert your data and model (or the value returned by the
objective function) to be double precision floating point numbers. One way to do this would be to use a function like
this:
def realimag(array):
    return np.array([(x.real, x.imag) for x in array]).flatten()

to convert the complex array into an array of alternating real and imaginary values. You can then use this function on
the result returned by your objective function:

                                                                                                                   13
Comment

PREVIOUS NEXT
Code Example
Python :: numpy difference between two arrays 
Python :: program in python to print first 10 natural number. 
Python :: python matrix determinant without numpy 
Python :: how to sleep() in python 
Python :: python 3.9 release date 
Python :: drop null values in dataframe 
Python :: how to join two tuples in python 
Python :: thresholding with OpenCV 
Python :: Finding the maximum element from a matrix with Python numpy.argmax() 
Python :: How to code a simple rock, paper, scissors game on Python 
Python :: Python match.re and match.string 
Python :: how to create an auto clicker in python 
Python :: api key python 
Python :: k means clustering python medium 
Python :: how to check if a list is empty in python 
Python :: how to generate two random numbers in python 
Python :: get source selenium python 
Python :: pong code python 
Python :: 1024x768 
Python :: waitkey in python 
Python :: sublime autocomplete python 
Python :: AttributeError: __enter__ in python cde 
Python :: python stack size 
Python :: starry spheres 
Python :: How to install proxy pool in scrapy? 
Python :: required depend filed odoo 
Python :: tkinter yt downloader with resolution 
Shell :: chrome inspect devices 
Shell :: conda install gensim 
Shell :: how to remove node_modules from git 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =