On Dec 12, 2019, at 16:40, Steven D'Aprano wrote:
>
>
> Surely a zero-dimensional array ought to have no elements at all?
Forgetting about the practical benefits of having a way to have scalars that
have a dtype and respond to ndarray methods and so on, here’s how to convince
yourself it make
We posted at same time. But the reason 0-D array isn't just a Python scalar
is because it still has array attributes, most notably dtype. Now maybe 15
years ago NumPy could have created a bunch more custom numeric scalars for
the different bit-lengths, but then we still wouldn't have the uniformit
On Thu, Dec 12, 2019 at 7:39 PM Steven D'Aprano wrote:
> Surely a zero-dimensional array ought to have no elements at all?
>
If you think of a 1-D array as falling on a line, and a 2-D array as
occupying a region of a plane, then the equivalent of a geometric point is
a 0-D array.
It's not real
On Thu, Dec 12, 2019 at 4:39 PM Steven D'Aprano wrote:
>
> Surely a zero-dimensional array ought to have no elements at all?
>
nope -- a zero-dimensional array is a scalar -- as distinct from a 1-d (or
2-d, or n-d) array that happens to have only one element.
in fact, numpy has a confusing (at
On Thu, Dec 12, 2019 at 04:20:58PM -0500, Random832 wrote:
> On Thu, Dec 12, 2019, at 15:59, Steven D'Aprano wrote:
> > But why have the empty index default to () rather than None or 0 or -1
> > or slice(None, None, None) or some other value? That's an arbitrary
> > and not a good one.
>
> My ma
On Dec 12, 2019, at 11:21, Jonathan Fine wrote:
>
>
> (We're still a bit off-topic here.) You asked me what I'd expect, if not the
> present values of:
>
> >>> seq[]
> SyntaxError: invalid syntax
>
> >>> getslice[1:2:3:4]
> SyntaxError: invalid syntax
>
> I'd have expected to got respectiv
On Thu, Dec 12, 2019 at 5:29 AM Siddharth Prajosh
wrote:
> Can we have an extra function for lists and string (and wherever slicing
> works) to explicitly mention that we're slicing?? Something like -
> *s=list(range(100));
> s.slice(10, 20).*
>
This exists already as ``itertools.islice`` and,
On 13/12/19 9:59 am, Steven D'Aprano wrote:
So a[] would be:
temp = # A syntax error.
a[temp]
not an empty tuple.
That's the way it is now, but it doesn't have to be that way.
There is some logic to the proposal. Currently the argument
passed to __getitem__ is what you would get
>
> tuple(t) isn't the same as tuple(1, 2, 3). Try it and see.
>
> > MyWeirdTuple(t) # is t the first argument, or is 1 the first argument?
>
> t is unambiguously the first argument.
>
I was responding to this sidebar, which was derailing the topic a bit and I
apologize. And my response still d
On Thu, Dec 12, 2019, at 15:59, Steven D'Aprano wrote:
> But why have the empty index default to () rather than None or 0 or -1
> or slice(None, None, None) or some other value? That's an arbitrary
> and not a good one.
My main reason for the suggestion was because that is the index used to acce
> > But what would happen if you call a user-defined class with a tuple as
> an argument?
> >
> > class MyWeirdTuple(tuple):
> > def __new__(self, tup, *args): ...
> >
> > t = (1,2,3)
> > tuple(t) # returns (1,2,3)
> > MyWeirdTuple(t) # is t the first argument, or is 1 the first argument?
>
>
On Thu, Dec 12, 2019 at 02:14:09PM -0500, Ricky Teachey wrote:
> But what would happen if you call a user-defined class with a tuple as an
> argument?
>
> class MyWeirdTuple(tuple):
> def __new__(self, tup, *args): ...
`__new__` is normally written with `cls` as the first argument, since it
On Dec 12, 2019, at 11:14, Ricky Teachey wrote:
>
> But what would happen if you call a user-defined class with a tuple as an
> argument?
>
> class MyWeirdTuple(tuple):
> def __new__(self, tup, *args): ...
>
> t = (1,2,3)
> tuple(t) # returns (1,2,3)
> MyWeirdTuple(t) # is t the first ar
On Thu, Dec 12, 2019 at 11:01:54AM -0800, Andrew Barnert via Python-ideas wrote:
> I don’t see any problem with a[] being the same as a[()]. We already
> have a[1,] is the same as a[(1,)] rather than a[1]
A comma is not an "index argument seperator". a[1,] is not the same as
a(1,) where the com
On 2019-12-12 19:01, Andrew Barnert via Python-ideas wrote:
On Dec 12, 2019, at 10:19, Ricky Teachey wrote:
As an aside, I've occasionally wished that [] would be the
same as [()], by analogy to [1,2].
In that universe, would (),),),),) be the same as ()?
Sorry:
Hi Andrew
(We're still a bit off-topic here.) You asked me what I'd expect, if not
the present values of:
>>> seq[]
SyntaxError: invalid syntax
>>> getslice[1:2:3:4]
SyntaxError: invalid syntax
I'd have expected to got respectively the outcome of
>>> seq.__getitem__()
>>> seq.__getitem__(sli
> Sorry: I suppose what I meant was: () would be the same as ().
>
>
> It already is the same:
>
> >>> ()
> ()
>
> So presumably it would still be the same in that universe. :)
>
How embarrassing.
>
> I don’t see any problem with a[] being the same as a[()]. We already
On Dec 12, 2019, at 10:19, Ricky Teachey wrote:
>
>>
>>> As an aside, I've occasionally wished that [] would be the same as [()], by
>>> analogy to [1,2].
>>
>> In that universe, would (),),),),) be the same as ()?
>
> Sorry: I suppose what I meant was: () would be the same as
>
>
>> As an aside, I've occasionally wished that [] would be the same as [()],
>> by analogy to [1,2].
>>
>
> In that universe, would (),),),),) be the same as ()?
>
Sorry: I suppose what I meant was: () would be the same as ().
___
Pytho
> As an aside, I've occasionally wished that [] would be the same as [()],
> by analogy to [1,2].
>
In that universe, would (),),),),) be the same as ()?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python
On Thu, Dec 12, 2019, at 12:31, Andrew Barnert via Python-ideas wrote:
> > >>> getslice[]
> > SyntaxError: invalid syntax
>
> What would you expect these to return?
As an aside, I've occasionally wished that [] would be the same as [()], by
analogy to [1,2].
On Dec 12, 2019, at 09:09, Jonathan Fine wrote:
>
> Finally, off-topic, I find it a bit odd that in the below we get syntax
> errors (rather than a run-time error).
>
> >>> getslice[]
> SyntaxError: invalid syntax
> >>> getslice[1:2]
> slice(1, 2, None)
> >>> getslice[1:2:3]
> slice(1, 2, 3)
>
On Dec 12, 2019, at 05:29, Siddharth Prajosh wrote:
>
> Python slicing looks really weird. How do I explain s=list(range(100));
> s[10:20] gives you a part of the list.
Well, first you have to explain what “slicing” means, and that for lists it
returns a new copy of the sub-list, and that it’
Hi Steve
You wrote that we don't need a seq.slice(a, b) method, because the existing
syntax does the job fine.
To change the subject slightly, it seems to me that we don't need both
seq[a:b] and slice(a, b). Certainly, we can get by without either. If we
didn't have seq[a:b] we could use slice(a,
On Thu, Dec 12, 2019 at 04:17:58PM +0530, Siddharth Prajosh wrote:
> Python slicing looks really weird.
I disagree that it looks weird. I think it looks beautiful.
> How do I explain *s=list(range(100));
> s[10:20] *gives you a part of the list.
The same way that you explain that the ^ operat
Hi Siddharth and Bruce
The original poster asked for something like:
>>> lst = list(range(100))
>>> lst.slice(10, 20)
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
For what it's worth, I think such a thing could be useful. And that
experience of it's use would be needed, before it could be added to P
On Thu, Dec 12, 2019, 7:28 AM Siddharth Prajosh wrote:
> Something like - *s=list(range(100)); s.slice(10, 20).*
>
You mean like say
s[slice(10,20)]
?
Done.
>
>
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email t
27 matches
Mail list logo