0

データを不均一な方法でビニングしたいと思います。

import numpy as np
import matplotlib.pyplot as plt

def fun(x):
  return >some function of x<

私が今欲しいのは、何かを次のように見せることです。

np.linespace(0.,200.,fun(x))

それを処理できるnumpy関数を使用する便利な方法はありますか?私はそれを見てnp.arangenp.linspace数値を処理し、関数を引数として使用することはできません。

私はそれを処理できる関数を書くことができますが、ネイティブソリューションの方がはるかに優れています。

4

1 に答える 1

3

x 値の範囲を作成し、カスタム関数を定義してから、各配列要素で関数を呼び出します。Numpy はこれを非常に簡単にします:

fun = lambda x: x**2 # Example function
N = 10 # Number of data points
x = np.linspace(0., 200., N) # Creates an array of N points
bins = fun(x) # Applies fun to all values in array x
于 2013-03-04T10:40:16.400 に答える