IndexError: expected dim 0 index in range [1, 3) Error Python
In Python, I am having strange error, where a = [x[1], x[2]]
works, but a = x[1:]
does not.
>>> out
farray([Y[0], Y[1], Y[2]])
>>> out[1]
Y[1]
>>> remaining_out = [out[1], out[2]]
>>> remaining_out[0]
Y[1]
>>> remaining_out = out[1:]
>>> remaining_out[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 485, in __getitem__
nsls = self._norm_slices(fsls) File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 890, in _norm_slices nsls.append(_norm_index(i, fsl, *self.shape[i]))
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 1127, in _norm_index
raise IndexError(fstr.format(dim, start, stop))
IndexError: expected dim 0 index in range [1, 3)
Please help.
python python-3.x
add a comment |
In Python, I am having strange error, where a = [x[1], x[2]]
works, but a = x[1:]
does not.
>>> out
farray([Y[0], Y[1], Y[2]])
>>> out[1]
Y[1]
>>> remaining_out = [out[1], out[2]]
>>> remaining_out[0]
Y[1]
>>> remaining_out = out[1:]
>>> remaining_out[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 485, in __getitem__
nsls = self._norm_slices(fsls) File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 890, in _norm_slices nsls.append(_norm_index(i, fsl, *self.shape[i]))
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 1127, in _norm_index
raise IndexError(fstr.format(dim, start, stop))
IndexError: expected dim 0 index in range [1, 3)
Please help.
python python-3.x
2
Doesfarray
accept subscript notations? It does not seem to be a Pythonlist
type.
– BernardL
Nov 26 '18 at 5:40
1
Some support might be found at this Function Array website. That being said, without additional code and a description of your goal, you will not likely have many responses.
– Andy
Nov 26 '18 at 5:41
add a comment |
In Python, I am having strange error, where a = [x[1], x[2]]
works, but a = x[1:]
does not.
>>> out
farray([Y[0], Y[1], Y[2]])
>>> out[1]
Y[1]
>>> remaining_out = [out[1], out[2]]
>>> remaining_out[0]
Y[1]
>>> remaining_out = out[1:]
>>> remaining_out[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 485, in __getitem__
nsls = self._norm_slices(fsls) File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 890, in _norm_slices nsls.append(_norm_index(i, fsl, *self.shape[i]))
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 1127, in _norm_index
raise IndexError(fstr.format(dim, start, stop))
IndexError: expected dim 0 index in range [1, 3)
Please help.
python python-3.x
In Python, I am having strange error, where a = [x[1], x[2]]
works, but a = x[1:]
does not.
>>> out
farray([Y[0], Y[1], Y[2]])
>>> out[1]
Y[1]
>>> remaining_out = [out[1], out[2]]
>>> remaining_out[0]
Y[1]
>>> remaining_out = out[1:]
>>> remaining_out[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 485, in __getitem__
nsls = self._norm_slices(fsls) File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 890, in _norm_slices nsls.append(_norm_index(i, fsl, *self.shape[i]))
File "/home/kmshah4/.local/lib/python3.6/site-packages/pyeda/boolalg/bfarray.py", line 1127, in _norm_index
raise IndexError(fstr.format(dim, start, stop))
IndexError: expected dim 0 index in range [1, 3)
Please help.
python python-3.x
python python-3.x
asked Nov 26 '18 at 5:29
Karan ShahKaran Shah
1,2361531
1,2361531
2
Doesfarray
accept subscript notations? It does not seem to be a Pythonlist
type.
– BernardL
Nov 26 '18 at 5:40
1
Some support might be found at this Function Array website. That being said, without additional code and a description of your goal, you will not likely have many responses.
– Andy
Nov 26 '18 at 5:41
add a comment |
2
Doesfarray
accept subscript notations? It does not seem to be a Pythonlist
type.
– BernardL
Nov 26 '18 at 5:40
1
Some support might be found at this Function Array website. That being said, without additional code and a description of your goal, you will not likely have many responses.
– Andy
Nov 26 '18 at 5:41
2
2
Does
farray
accept subscript notations? It does not seem to be a Python list
type.– BernardL
Nov 26 '18 at 5:40
Does
farray
accept subscript notations? It does not seem to be a Python list
type.– BernardL
Nov 26 '18 at 5:40
1
1
Some support might be found at this Function Array website. That being said, without additional code and a description of your goal, you will not likely have many responses.
– Andy
Nov 26 '18 at 5:41
Some support might be found at this Function Array website. That being said, without additional code and a description of your goal, you will not likely have many responses.
– Andy
Nov 26 '18 at 5:41
add a comment |
1 Answer
1
active
oldest
votes
Objects in Python do not automatically support slice notation just because they support indexing. That has to be programmed in. There may be syntax more convenient than what you're using though.
If it's iterable, you can convert to a list first, and then slice it, like
a = [*x][1:]
For especially large iterables (does not seem to be the case here), this may be inefficient. In that case, islice
it before you unpack into the list.
from itertools import islice
a = [*islice(x, 1, None)]
But objects do not automatically support iteration just because they support indexing either. If that's the case, you can still iterate manually with range()
and a comprehension,
a = [x[i] for i in range(1, len(x))]
Though this isn't really shorter until you have a few more elements to deal with. If you need this pattern a lot you could abstract it into a function.
And finally, objects do not necessarily support len
just because they support indexing. If you don't know the length in advance, about all you can do is loop through and catch the LookupError
at that point.
I did it withlist(x)[1:]
. Is that good way?
– Karan Shah
Nov 26 '18 at 7:09
1
It's the same as[*x][1:]
, pretty much, just a bit more verbose.list(x)
would still work on Python 2.7, but the[*x]
syntax is newer.
– gilch
Nov 26 '18 at 16:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475198%2findexerror-expected-dim-0-index-in-range-1-3-error-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Objects in Python do not automatically support slice notation just because they support indexing. That has to be programmed in. There may be syntax more convenient than what you're using though.
If it's iterable, you can convert to a list first, and then slice it, like
a = [*x][1:]
For especially large iterables (does not seem to be the case here), this may be inefficient. In that case, islice
it before you unpack into the list.
from itertools import islice
a = [*islice(x, 1, None)]
But objects do not automatically support iteration just because they support indexing either. If that's the case, you can still iterate manually with range()
and a comprehension,
a = [x[i] for i in range(1, len(x))]
Though this isn't really shorter until you have a few more elements to deal with. If you need this pattern a lot you could abstract it into a function.
And finally, objects do not necessarily support len
just because they support indexing. If you don't know the length in advance, about all you can do is loop through and catch the LookupError
at that point.
I did it withlist(x)[1:]
. Is that good way?
– Karan Shah
Nov 26 '18 at 7:09
1
It's the same as[*x][1:]
, pretty much, just a bit more verbose.list(x)
would still work on Python 2.7, but the[*x]
syntax is newer.
– gilch
Nov 26 '18 at 16:55
add a comment |
Objects in Python do not automatically support slice notation just because they support indexing. That has to be programmed in. There may be syntax more convenient than what you're using though.
If it's iterable, you can convert to a list first, and then slice it, like
a = [*x][1:]
For especially large iterables (does not seem to be the case here), this may be inefficient. In that case, islice
it before you unpack into the list.
from itertools import islice
a = [*islice(x, 1, None)]
But objects do not automatically support iteration just because they support indexing either. If that's the case, you can still iterate manually with range()
and a comprehension,
a = [x[i] for i in range(1, len(x))]
Though this isn't really shorter until you have a few more elements to deal with. If you need this pattern a lot you could abstract it into a function.
And finally, objects do not necessarily support len
just because they support indexing. If you don't know the length in advance, about all you can do is loop through and catch the LookupError
at that point.
I did it withlist(x)[1:]
. Is that good way?
– Karan Shah
Nov 26 '18 at 7:09
1
It's the same as[*x][1:]
, pretty much, just a bit more verbose.list(x)
would still work on Python 2.7, but the[*x]
syntax is newer.
– gilch
Nov 26 '18 at 16:55
add a comment |
Objects in Python do not automatically support slice notation just because they support indexing. That has to be programmed in. There may be syntax more convenient than what you're using though.
If it's iterable, you can convert to a list first, and then slice it, like
a = [*x][1:]
For especially large iterables (does not seem to be the case here), this may be inefficient. In that case, islice
it before you unpack into the list.
from itertools import islice
a = [*islice(x, 1, None)]
But objects do not automatically support iteration just because they support indexing either. If that's the case, you can still iterate manually with range()
and a comprehension,
a = [x[i] for i in range(1, len(x))]
Though this isn't really shorter until you have a few more elements to deal with. If you need this pattern a lot you could abstract it into a function.
And finally, objects do not necessarily support len
just because they support indexing. If you don't know the length in advance, about all you can do is loop through and catch the LookupError
at that point.
Objects in Python do not automatically support slice notation just because they support indexing. That has to be programmed in. There may be syntax more convenient than what you're using though.
If it's iterable, you can convert to a list first, and then slice it, like
a = [*x][1:]
For especially large iterables (does not seem to be the case here), this may be inefficient. In that case, islice
it before you unpack into the list.
from itertools import islice
a = [*islice(x, 1, None)]
But objects do not automatically support iteration just because they support indexing either. If that's the case, you can still iterate manually with range()
and a comprehension,
a = [x[i] for i in range(1, len(x))]
Though this isn't really shorter until you have a few more elements to deal with. If you need this pattern a lot you could abstract it into a function.
And finally, objects do not necessarily support len
just because they support indexing. If you don't know the length in advance, about all you can do is loop through and catch the LookupError
at that point.
edited Nov 26 '18 at 17:02
answered Nov 26 '18 at 6:22
gilchgilch
3,8901716
3,8901716
I did it withlist(x)[1:]
. Is that good way?
– Karan Shah
Nov 26 '18 at 7:09
1
It's the same as[*x][1:]
, pretty much, just a bit more verbose.list(x)
would still work on Python 2.7, but the[*x]
syntax is newer.
– gilch
Nov 26 '18 at 16:55
add a comment |
I did it withlist(x)[1:]
. Is that good way?
– Karan Shah
Nov 26 '18 at 7:09
1
It's the same as[*x][1:]
, pretty much, just a bit more verbose.list(x)
would still work on Python 2.7, but the[*x]
syntax is newer.
– gilch
Nov 26 '18 at 16:55
I did it with
list(x)[1:]
. Is that good way?– Karan Shah
Nov 26 '18 at 7:09
I did it with
list(x)[1:]
. Is that good way?– Karan Shah
Nov 26 '18 at 7:09
1
1
It's the same as
[*x][1:]
, pretty much, just a bit more verbose. list(x)
would still work on Python 2.7, but the [*x]
syntax is newer.– gilch
Nov 26 '18 at 16:55
It's the same as
[*x][1:]
, pretty much, just a bit more verbose. list(x)
would still work on Python 2.7, but the [*x]
syntax is newer.– gilch
Nov 26 '18 at 16:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475198%2findexerror-expected-dim-0-index-in-range-1-3-error-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Does
farray
accept subscript notations? It does not seem to be a Pythonlist
type.– BernardL
Nov 26 '18 at 5:40
1
Some support might be found at this Function Array website. That being said, without additional code and a description of your goal, you will not likely have many responses.
– Andy
Nov 26 '18 at 5:41