2014-12-26 2 views
1

에 목록을 매핑하는 동안 길이 내가 아직 이해하지 Theano에 있지만 많은 연구에도 불구하고 초보자입니다 알려진하지 왜 다음 코드를에 ValueError : Theano

from matplotlib.pyplot import plot 
from numpy import linspace 
import theano.tensors as T 
A = linspace(0,1,100) 
plot(A, T.sqrt(A)) 

반환이 오류 메시지

ValueError        Traceback (most recent call last) 
<ipython-input-21-48fbaf974de7> in <module>() 
----> 1 plot(L1, L1+Lx) 

C:\Python27\lib\site-packages\matplotlib\pyplot.pyc in plot(*args, **kwargs) 
    2985   ax.hold(hold) 
    2986  try: 
-> 2987   ret = ax.plot(*args, **kwargs) 
    2988   draw_if_interactive() 
    2989  finally: 

C:\Python27\lib\site-packages\matplotlib\axes.pyc in plot(self, *args, **kwargs) 
    4135   lines = [] 
    4136 
-> 4137   for line in self._get_lines(*args, **kwargs): 
    4138    self.add_line(line) 
    4139    lines.append(line) 

C:\Python27\lib\site-packages\matplotlib\axes.pyc in _grab_next_args(self, *args, **kwargs) 
    315     return 
    316    if len(remaining) <= 3: 
--> 317     for seg in self._plot_args(remaining, kwargs): 
    318      yield seg 
    319     return 

C:\Python27\lib\site-packages\matplotlib\axes.pyc in _plot_args(self, tup, kwargs) 
    293    x = np.arange(y.shape[0], dtype=float) 
    294 
--> 295   x, y = self._xy_from_xy(x, y) 
    296 
    297   if self.command == 'plot': 

C:\Python27\lib\site-packages\matplotlib\axes.pyc in _xy_from_xy(self, x, y) 
    212   if self.axes.xaxis is not None and self.axes.yaxis is not None: 
    213    bx = self.axes.xaxis.update_units(x) 
--> 214    by = self.axes.yaxis.update_units(y) 
    215 
    216    if self.command != 'plot': 

C:\Python27\lib\site-packages\matplotlib\axis.pyc in update_units(self, data) 
    1334   """ 
    1335 
-> 1336   converter = munits.registry.get_converter(data) 
    1337   if converter is None: 
    1338    return False 

C:\Python27\lib\site-packages\matplotlib\units.pyc in get_converter(self, x) 
    146    except AttributeError: 
    147     # not a masked_array 
--> 148     converter = self.get_converter(xravel[0]) 
    149     return converter 
    150 

C:\Python27\lib\site-packages\matplotlib\units.pyc in get_converter(self, x) 
    150 
    151   if converter is None and iterable(x): 
--> 152    for thisx in x: 
    153     # Make sure that recursing might actually lead to a solution, 
    154     # if we are just going to re-examine another item of the same 

C:\Python27\lib\site-packages\theano\tensor\var.pyc in __iter__(self) 
    416  def __iter__(self): 
    417   try: 
--> 418    for i in xrange(theano.tensor.basic.get_vector_length(self)): 
    419     yield self[i] 
    420   except TypeError: 

C:\Python27\lib\site-packages\theano\tensor\basic.pyc in get_vector_length(v) 
    3732  if v.owner and isinstance(v.owner.op, Shape): 
    3733   return v.owner.inputs[0].type.ndim 
-> 3734  raise ValueError("length not known") 
    3735 
    3736 

ValueError: length not known 

콘솔에 T.sqrt (A)를 입력하면 "Elemwise {sqrt, no_inplace} .0"이 반환되고 T.sqrt (A) 값을 가져올 수 없습니다. 나는 tano와 함께 matplotlib를 사용할 수 있는지 궁금하다. 그렇지 않으면 어떻게 theano 함수에 의해 ndarray 유형으로 다시 매핑되는 numpy 배열 목록을 얻을 수 있을지 궁금하다.

답변

1

"Elemwise {sqrt, no_inplace} .0"을 얻는 이유는 Theano가 기호이므로 평가할 때까지 텐서가 값을 갖지 않기 때문입니다. 이 문제를 해결하려면 텐서를 평가하고 숫자 값을 얻으려면

from matplotlib.pyplot import plot 
from numpy import linspace 
import theano.tensor as T 
A = linspace(0,1,100) 
plot(A, T.sqrt(A).eval()) 

또한 theano.tensor가 아닌 theano.tensor를 가져와야합니다.