Q2:AttributeError:'builtin_function_or_method'对象没有属性'size' [英] Q2: AttributeError: 'builtin_function_or_method' object has no attribute 'size'

查看:267
本文介绍了Q2:AttributeError:'builtin_function_or_method'对象没有属性'size'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Could anyone tell me why I'm getting the error type: AttributeError: 'builtin_function_or_method' object has no attribute

'size'像57一样?
为此合成音:out=np.zeros((x.size,y.size))

'size' in like 57?
for this synthax: out=np.zeros((x.size,y.size))

import numpy as np
import sympy as sp
from numpy import exp,sqrt,pi
from sympy import Integral, log, exp, sqrt, pi
import math
from numpy import array
import matplotlib.pyplot as plt 
import scipy.integrate
from scipy.special import erf
from scipy.stats import norm, gaussian_kde
from quantecon import LAE
from sympy.abc import q
#from sympy import symbols
#var('q')
#q= symbols('q')

## == Define parameters == #
mu=80
sigma=20
b=0.2
Q=80
Q1=Q*(1-b)
Q2=Q*(1+b)
d = (sigma*np.sqrt(2*np.pi))
phi = norm()
n = 500

#Phi(z) = 1/2[1 + erf(z/sqrt(2))].

def p_k_positive(x, y):
   # x, y = np.array(x, dtype=float), np.array(y, dtype=float)
    Positive_RG = norm.pdf(x[:, None] - y[None, :]+Q1, mu, sigma)
    print('Positive_R = ', Positive_RG)
    return Positive_RG 

def p_k_negative(x, y):
   # x, y = np.array(x, dtype=float), np.array(y, dtype=float)
    Negative_RG = norm.pdf(x[:, None] - y[None, :]+Q2, mu, sigma) 
    print('Negative_RG = ', Negative_RG)
    return Negative_RG 

def p_k_zero(x, y):
   # x, y = np.array(x, dtype=float), np.array(y, dtype=float)
    Zero_RG = (1/(2*math.sqrt(2*math.pi)))*(erf((x[:, None]+Q2-mu)/(sigma*math.sqrt(2)))-erf((x[:, None]+Q1-mu)/(sigma*math.sqrt(2))))
    #Zero_RG =norm.pdf
    print('Zero_RG',Zero_RG)
    return Zero_RG

def myFilter(x,y):
    x, y = x.squeeze, y.squeeze
    out=np.zeros((x.size,y.size))
    xyDiff = x[:, None] - y[None, :]
    out=np.where(np.bitwise_and(y[None, :] > 0.0, xyDiff >= -Q1), p_k_positive(x, y), out) # unless the sum functions are different
    out=np.where(np.bitwise_and(y[None, :] < 0.0, x[:, None] >= -Q1), p_k_negative(x, y), out)
    out=np.where(np.bitwise_and(y[None, :] ==0.0, xyDiff >= -Q1), p_k_zero(x, y), out)
    return out


Z = phi.rvs(n)
X = np.empty(n)
for t in range(n-1):
    X[t+1] = X[t] + Z[t]
    #X[t+1] = np.abs(X[t]) + Z[t]
psi_est = LAE(myFilter, X)
k_est = gaussian_kde(X)

fig, ax = plt.subplots(figsize=(10,7))
ys = np.linspace(-200.0, 200.0, 200)
ax.plot(ys, psi_est(ys), 'g-', lw=2, alpha=0.6, label='look ahead estimate')
ax.plot(ys, k_est(ys), 'k-', lw=2, alpha=0.6, label='kernel based estimate')
ax.legend(loc='upper left')
plt.show()

推荐答案

x, y = x.squeeze, y.squeeze

应该是

x, y = x.squeeze(), y.squeeze()

或者您正在尝试使用函数的size.

or you're trying to take the size of a function.

这篇关于Q2:AttributeError:'builtin_function_or_method'对象没有属性'size'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆