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 回答