【问题标题】:How do I Iterate the below equation to determine the roots我如何迭代下面的方程来确定根
【发布时间】:2017-11-10 06:16:17
【问题描述】:

上一个问题

如何使用代码确定为以下等式的 sigma 循环迭代的最佳方法。

import statistics as stats
import warnings
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import scipy
import scipy.stats
import sympy
from scipy import stats as st
from itertools import islice, count
import itertools

def func_shape_factor(vi, k):
k_list = []  # other name
for vi in np.nditer(vi, flags=['buffered'], op_dtypes=['float64']):
    # k initial guess of 1.5, changable
    k = 1.5
    k = (np.nan_to_num((np.sum((vi) ** (k) * np.log(vi)) / np.sum((vi) ** \
        (k)) - ((np.sum(np.log(vi)) / len(vi))))))
    k_list.append(k)  # append k to the list of ks
return np.array(k)  # cast it to an array after the loop.

【问题讨论】:

  • 非常感谢您附加到 k 列表的解决方案有效。我现在将尝试更正其余代码,这更像是一个概念问题。

标签: python scipy curve-fitting newtons-method


【解决方案1】:

发生异常是因为 concatenate 是 NumPy 函数而不是 numpy.ndarray 方法。所以你必须把它称为:

np.concatenate(arrays)

但是它在您的代码中并没有真正意义,因为您已经在内循环中重新分配了k。你可能想appendk-list 所以你需要不同的变量名:

def func_shape_factor(vi, k):
    k_list = []  # other name
    for vi in np.nditer(vi, flags=['buffered'], op_dtypes=['float64']):
        # k initial guess of 1.5, changable
        k = 1.5
        k = (np.nan_to_num((np.sum((vi) ** (k) * np.log(vi)) / np.sum((vi) ** (k)) - ((np.sum(np.log(vi)) / len(vi))))))
        k_list.append(k)  # append k to the list of ks
    return np.array(k)  # cast it to an array after the loop.

不确定这是否仍然满足您的需求。

【讨论】:

  • @MAULIDIBARASA 不确定您的意思,但如果方法发生变化,最好提出一个新问题 :)
猜你喜欢
  • 2011-01-11
  • 2021-06-15
  • 1970-01-01
  • 1970-01-01
  • 2016-12-04
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多