classification
Title: Unpacking numpy array give list
Type: behavior Stage: resolved
Components: Regular Expressions Versions: Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SilentGhost, ezio.melotti, mrabarnett, r.david.murray, rpampana
Priority: normal Keywords:

Created on 2016-09-28 14:07 by rpampana, last changed 2016-09-28 14:25 by r.david.murray. This issue is now closed.

Messages (3)
msg277622 - (view) Author: RAMESH PAMPANA (rpampana) Date: 2016-09-28 14:07
Unpacking numpy array gives list rather numpy array.

>>> import numpy as np
>>> a = np.array([1,2,3,4])
>>> x, *y, z = a
>>> type(a)
<class 'numpy.ndarray'>
>>> type(y)
<class 'list'>>
>> type(x)
<class 'numpy.int32'>
msg277627 - (view) Author: SilentGhost (SilentGhost) * (Python triager) Date: 2016-09-28 14:24
It doesn't matter what you're unpacking, *y will collect the unpacked elements into a list.
msg277628 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-09-28 14:25
Yes, you are unpacking into a list, that's what the * syntax does in this context.  Since the rhs can be a mix of types, there's really no other reasonable meaning for the syntax.  (The same is true for tuples, by the way).
History
Date User Action Args
2016-09-28 14:25:41r.david.murraysetnosy: + r.david.murray
messages: + msg277628
components: + Regular Expressions, - Interpreter Core
2016-09-28 14:24:23SilentGhostsetstatus: open -> closed

components: + Interpreter Core, - Regular Expressions

nosy: + SilentGhost
messages: + msg277627
resolution: not a bug
stage: resolved
2016-09-28 14:07:24rpampanacreate