Creating a hot vector (numpy)
Reto Brunner
brunnre8 at gmail.com
Mon Apr 18 00:05:19 EDT 2016
Hi,
It is called broadcasting an array, have a look here:
http://docs.scipy.org/doc/numpy-1.10.1/user/basics.broadcasting.html
Greetings,
Reto
On Mon, Apr 18, 2016, 02:54 Paulo da Silva <p_s_d_a_s_i_l_v_a_ns at netcabo.pt>
wrote:
> Hi all.
>
> I have seen this "trick" to create a hot vector.
>
> In [45]: x
> Out[45]: array([0, 1])
>
> In [46]: y
> Out[46]: array([1, 1, 1, 0, 0, 1, 0, 0], dtype=uint8)
>
> In [47]: y[:,None]
> Out[47]:
> array([[1],
> [1],
> [1],
> [0],
> [0],
> [1],
> [0],
> [0]], dtype=uint8)
>
> In [48]: x==y[:,None]
> Out[48]:
> array([[False, True],
> [False, True],
> [False, True],
> [ True, False],
> [ True, False],
> [False, True],
> [ True, False],
> [ True, False]], dtype=bool)
>
> In [49]: (x==y[:,None]).astype(np.float32)
> Out[49]:
> array([[ 0., 1.],
> [ 0., 1.],
> [ 0., 1.],
> [ 1., 0.],
> [ 1., 0.],
> [ 0., 1.],
> [ 1., 0.],
> [ 1., 0.]], dtype=float32)
>
> How does this (step 48) work?
>
> Thanks
> --
> https://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list