1

Previous Question

How to determine the best way to iterate through a loop for a sigma for the below equation using the code.

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.
Gwiji
  • 71
  • 8
  • Thanks a lot your solution to append to the k-list worked. I will now try to correct the rest of the code, which is more a matter of concept. – Gwiji Jun 10 '17 at 22:38

1 Answers1

1

The exception happens because concatenate is a NumPy function not a numpy.ndarray method. So you have to call it as:

np.concatenate(arrays)

However it doesn't really make sense in your code because you already re-assigned k in the inner-loop. You probably want to append to the k-list so you need different variable names:

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.

Not sure if that still does what you need though.

MSeifert
  • 145,886
  • 38
  • 333
  • 352
  • @MAULIDIBARASA Not sure what you mean but in case the methodology changed it would be better to ask a new question instead :) – MSeifert Aug 11 '17 at 12:05