简体   繁体   中英

Output of Built-In Numpy Function to an Array?

The code I am writing (among other things) calculates the coefficients of the Legendre polynomial fit of my data. I am writing it to do this in a piecewise fashion on my dataset, due to the presence of discontinuities in the data. I'm having no problem getting the coefficients returned using

numpy.polynomial.legendre.Legendre.fit()

but I need my output to be arrays. When I try to have the coefficients output to an array using array.append() on an empty array, I'm getting the following error message:

TypeError: 'builtin_function_or_method' object has no attribute '__getitem__'

Could someone advise me on how to get around this? Thanks!

EDIT: My problem stemmed from using square brackets where I should have used parentheses. However, I couldn't see the forest for the trees, and it helped to get responses!

Try using

numpy.append(array, values)

in place of

array.append(values).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM