[SciPy-Dev] dtype int16

Johnny Chan johnnychan0302 at gmail.com
Thu May 7 13:47:39 EDT 2015


Thank you Alex and Sturla for replying. Mini-summary: the tutorial is
technically correct (no correction is required).

It turns out that there are multiple ways to do this - below list the 3
ways of doing it. (I got the error message the first time due to a syntax
error on my part - apologies).

Thank you all. I believe it is ok to close off this topic now :)

Johnny.
p.s. see below email trial for the 3 methods of performing the same
operation.

On Thu, May 7, 2015 at 3:54 PM, Johnny Chan <johnnychan0302 at gmail.com>
wrote:

> Thank you Alex! You are so right!
>
> I have just tried all 3 methods and everything works and makes sense to me
> now. Thank you so much!
>
>
> from numpy import *
>
> ones( (2,3,4), dtype=int16 )
> Out[2]:
> array([[[1, 1, 1, 1],
>         [1, 1, 1, 1],
>         [1, 1, 1, 1]],
>
>        [[1, 1, 1, 1],
>         [1, 1, 1, 1],
>         [1, 1, 1, 1]]], dtype=int16)
>
> Restarting kernel...
>
>
> import numpy as np
>
> np.ones( (2,3,4), dtype=np.int16 )
> Out[2]:
> array([[[1, 1, 1, 1],
>         [1, 1, 1, 1],
>         [1, 1, 1, 1]],
>
>        [[1, 1, 1, 1],
>         [1, 1, 1, 1],
>         [1, 1, 1, 1]]], dtype=int16)
>
> np.ones( (2,3,4), dtype="int16" )
> Out[3]:
> array([[[1, 1, 1, 1],
>         [1, 1, 1, 1],
>         [1, 1, 1, 1]],
>
>        [[1, 1, 1, 1],
>         [1, 1, 1, 1],
>         [1, 1, 1, 1]]], dtype=int16)
>
>
> Best regards,
> Johnny
>
>
> On Thu, May 7, 2015 at 3:47 PM, Alexander Griffing <argriffi at ncsu.edu>
> wrote:
>
>> The tutorial is not technically wrong, because it has
>> from numpy import *
>>
>> This lets you write
>> ones( (2,3,4), dtype=int16 )
>> as in the tutorial, instead of requiring
>> np.ones( (2,3,4), dtype=np.int16 )
>> or alternatively
>> np.ones( (2,3,4), dtype="int16" )
>>
>> It's confusing that there are so many ways to write this.  It doesn't
>> follow the principle of https://wiki.python.org/moin/TOOWTDI.
>>
>> Cheers,
>> Alex
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scipy-dev/attachments/20150507/1b04cc2f/attachment.html>


More information about the SciPy-Dev mailing list