问题描述
我想做一个 numpy.where()
语句,如果 PC_list
的长度等于数字的长度,那么我想要计算 PC_list[0:number].std()
的标准偏差和我还想删除 PC_list
中的第一个数字:np.setdiff1d(PC_list,PC_list[0])
。我希望这个过程一直持续到列表编号不等于编号 len(PC_list[0:number]!=number
。我尝试以这种方式格式化 numpy.where()
,但是这样做时出现语法错误,因此我需要对下面的 numpy.where()
函数进行更正。
代码:
number = 3
list_= np.array([457.334015,424.440002,394.795990,408.903992,398.821014,402.152008,435.790985,423.204987,411.574005,404.424988,399.519989,377.181000,375.467010,386.944000,383.614990,375.071991,359.511993,328.865997,320.510010,330.079010,336.187012,352.940002,365.026001,361.562012,362.299011,378.549011,390.414001,400.869995,394.773010,382.556000])
np.where(len(PC_list[0:number]==number,default = 'NA',PC_list[0:number].std(),np.setdiff1d(PC_list,PC_list[0])))
Vanilla Python 代码:
from copy import deepcopy
list_ = deepcopy(PC_list)
if len(list_[0:number]==number:
STD = list_[0:number].std()
list_ = np.setdiff1d(list_,list_[0])
错误:
File "<ipython-input-93-215f70228bdc>",line 1
np.where(len(PC_list[0:number]==number,PC_list[0])))
^
SyntaxError: positional argument follows keyword argument
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)