Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #101349

Re: Question about a class member

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Question about a class member
Date 2016-01-07 11:38 -0700
Message-ID <mailman.52.1452191974.2305.python-list@python.org> (permalink)
References <a199a9b7-784e-4e12-8030-4e3fffd636a7@googlegroups.com>

Show all headers | View raw


On Thu, Jan 7, 2016 at 10:23 AM, Robert <rxjwg98@gmail.com> wrote:
> When I read its (class) definition, I find the following part (which may not
> be sure 100% the above origination yet, but it is the only line being
> 'sample').
> //////////////
>         self.gmms_ = []
>         for x in range(self.n_components):
>             if covariance_type is None:
>                 gmm = GMM(n_mix)
>             else:
>                 gmm = GMM(n_mix, covariance_type=covariance_type)
>             self.gmms_.append(gmm)

self.gmms_ is a list. The contents of the list are instances of the
GMM class, which I can't tell you anything about because it isn't
reproduced in your message.

>     def _generate_sample_from_state(self, state, random_state=None):
>         return self.gmms_[state].sample(1, random_state=random_state).flatten()
> ////////////
>
> The above code looks like self.gmms is a list, which has an attribute
> 'sample'. But when I play with a list, there is no 'sample' attribute.

self.gmms_[state] refers to a particular element of the list, which
per the above should be an instance of the GMM class. The sample
method would be part of the GMM class.

> ..........
> a=[1, 32.0, 4]
>
> a
> Out[68]: [1, 32.0, 4]
>
> type(a)
> Out[69]: list
>
> a[0].sample(1,5)
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
> <ipython-input-70-ce2e8159b438> in <module>()
> ----> 1 a[0].sample(1,5)
>
> AttributeError: 'int' object has no attribute 'sample'

Because you're playing with a list of ints and floats, not GMMs.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question about a class member Robert <rxjwg98@gmail.com> - 2016-01-07 09:23 -0800
  Re: Question about a class member Robert <rxjwg98@gmail.com> - 2016-01-07 09:39 -0800
  Re: Question about a class member John Gordon <gordon@panix.com> - 2016-01-07 18:37 +0000
  Re: Question about a class member Ian Kelly <ian.g.kelly@gmail.com> - 2016-01-07 11:38 -0700
  Re: Question about a class member Steven D'Aprano <steve@pearwood.info> - 2016-01-08 09:05 +1100
    Re: Question about a class member Robert <rxjwg98@gmail.com> - 2016-01-07 15:02 -0800

csiph-web