Reshape Numpy Array: 'list' object is not callable
I have a method, get_input_representation
that returns a numpy array
np.array = input_stack + input_buffer
return np.array
In another a different part of the program, I call the above method, save its return value and reshape it.
state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)
However, I get:
reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable
I have also tried:
reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)
But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?
python arrays numpy
add a comment |
I have a method, get_input_representation
that returns a numpy array
np.array = input_stack + input_buffer
return np.array
In another a different part of the program, I call the above method, save its return value and reshape it.
state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)
However, I get:
reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable
I have also tried:
reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)
But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?
python arrays numpy
2
You importednumpy
asnp
.np.array
is a function that is used to create a numpy array (classndarray
). But you then rename thisnp.array = ...
. Now it no longer is a function, but the result of that first line. The originalnp.array
function is no longer available.
– hpaulj
Nov 12 '18 at 4:18
even ifnp.array
is in a different file from the caller function?
– Matt
Nov 12 '18 at 4:21
Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55
add a comment |
I have a method, get_input_representation
that returns a numpy array
np.array = input_stack + input_buffer
return np.array
In another a different part of the program, I call the above method, save its return value and reshape it.
state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)
However, I get:
reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable
I have also tried:
reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)
But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?
python arrays numpy
I have a method, get_input_representation
that returns a numpy array
np.array = input_stack + input_buffer
return np.array
In another a different part of the program, I call the above method, save its return value and reshape it.
state_rep = self.extractor.get_input_representation(words, pos, state)
reshaped_state = np.array(state_rep).reshape(-1,6)
However, I get:
reshaped_state = np.array(state_rep).reshape(-1,6) TypeError: 'list'
object is not callable
I have also tried:
reshaped_state = np.array(self.extractor.get_input_representation(words, pos, state)).reshape(-1,6)
But I get the same list object is not callable. Where is the error in my code and how can I go about fixing it?
python arrays numpy
python arrays numpy
edited Nov 12 '18 at 4:19
Matt
asked Nov 12 '18 at 3:54
MattMatt
4871724
4871724
2
You importednumpy
asnp
.np.array
is a function that is used to create a numpy array (classndarray
). But you then rename thisnp.array = ...
. Now it no longer is a function, but the result of that first line. The originalnp.array
function is no longer available.
– hpaulj
Nov 12 '18 at 4:18
even ifnp.array
is in a different file from the caller function?
– Matt
Nov 12 '18 at 4:21
Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55
add a comment |
2
You importednumpy
asnp
.np.array
is a function that is used to create a numpy array (classndarray
). But you then rename thisnp.array = ...
. Now it no longer is a function, but the result of that first line. The originalnp.array
function is no longer available.
– hpaulj
Nov 12 '18 at 4:18
even ifnp.array
is in a different file from the caller function?
– Matt
Nov 12 '18 at 4:21
Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55
2
2
You imported
numpy
as np
. np.array
is a function that is used to create a numpy array (class ndarray
). But you then rename this np.array = ...
. Now it no longer is a function, but the result of that first line. The original np.array
function is no longer available.– hpaulj
Nov 12 '18 at 4:18
You imported
numpy
as np
. np.array
is a function that is used to create a numpy array (class ndarray
). But you then rename this np.array = ...
. Now it no longer is a function, but the result of that first line. The original np.array
function is no longer available.– hpaulj
Nov 12 '18 at 4:18
even if
np.array
is in a different file from the caller function?– Matt
Nov 12 '18 at 4:21
even if
np.array
is in a different file from the caller function?– Matt
Nov 12 '18 at 4:21
Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55
Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55
add a comment |
2 Answers
2
active
oldest
votes
I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer
and then return np.array
you should have return input_stack + input_buffer
in your function
add a comment |
Would you need brackets instead of parens?
np.array[state_rep].reshape(-1,6)
I think you are trying to index into the np array right?
when i do this, i getTypeError: list indices must be integers or slices, not list
– Matt
Nov 12 '18 at 4:04
Hm, so it seems you aren't passing an index to the array. Can you add more info about whatself.extractor.get_input_representation(words, pos, state)
and what that returns?
– LeKhan9
Nov 12 '18 at 4:16
yes,get_input_representation
returns a np array (see edited post, hopefully made more clear)
– Matt
Nov 12 '18 at 4:19
1
You shouldn't assign it to np.array, try just creating a basic variable likeoutput_list
or something and then returning that.
– LeKhan9
Nov 12 '18 at 4:21
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%2f53255750%2freshape-numpy-array-list-object-is-not-callable%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer
and then return np.array
you should have return input_stack + input_buffer
in your function
add a comment |
I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer
and then return np.array
you should have return input_stack + input_buffer
in your function
add a comment |
I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer
and then return np.array
you should have return input_stack + input_buffer
in your function
I think you should not be assigning default Numpy methods to a variable (even if it is inside a function) ie instead of np.array = input_stack + input_buffer
and then return np.array
you should have return input_stack + input_buffer
in your function
answered Nov 12 '18 at 4:24
Piyush SinghPiyush Singh
865
865
add a comment |
add a comment |
Would you need brackets instead of parens?
np.array[state_rep].reshape(-1,6)
I think you are trying to index into the np array right?
when i do this, i getTypeError: list indices must be integers or slices, not list
– Matt
Nov 12 '18 at 4:04
Hm, so it seems you aren't passing an index to the array. Can you add more info about whatself.extractor.get_input_representation(words, pos, state)
and what that returns?
– LeKhan9
Nov 12 '18 at 4:16
yes,get_input_representation
returns a np array (see edited post, hopefully made more clear)
– Matt
Nov 12 '18 at 4:19
1
You shouldn't assign it to np.array, try just creating a basic variable likeoutput_list
or something and then returning that.
– LeKhan9
Nov 12 '18 at 4:21
add a comment |
Would you need brackets instead of parens?
np.array[state_rep].reshape(-1,6)
I think you are trying to index into the np array right?
when i do this, i getTypeError: list indices must be integers or slices, not list
– Matt
Nov 12 '18 at 4:04
Hm, so it seems you aren't passing an index to the array. Can you add more info about whatself.extractor.get_input_representation(words, pos, state)
and what that returns?
– LeKhan9
Nov 12 '18 at 4:16
yes,get_input_representation
returns a np array (see edited post, hopefully made more clear)
– Matt
Nov 12 '18 at 4:19
1
You shouldn't assign it to np.array, try just creating a basic variable likeoutput_list
or something and then returning that.
– LeKhan9
Nov 12 '18 at 4:21
add a comment |
Would you need brackets instead of parens?
np.array[state_rep].reshape(-1,6)
I think you are trying to index into the np array right?
Would you need brackets instead of parens?
np.array[state_rep].reshape(-1,6)
I think you are trying to index into the np array right?
answered Nov 12 '18 at 4:01
LeKhan9LeKhan9
931112
931112
when i do this, i getTypeError: list indices must be integers or slices, not list
– Matt
Nov 12 '18 at 4:04
Hm, so it seems you aren't passing an index to the array. Can you add more info about whatself.extractor.get_input_representation(words, pos, state)
and what that returns?
– LeKhan9
Nov 12 '18 at 4:16
yes,get_input_representation
returns a np array (see edited post, hopefully made more clear)
– Matt
Nov 12 '18 at 4:19
1
You shouldn't assign it to np.array, try just creating a basic variable likeoutput_list
or something and then returning that.
– LeKhan9
Nov 12 '18 at 4:21
add a comment |
when i do this, i getTypeError: list indices must be integers or slices, not list
– Matt
Nov 12 '18 at 4:04
Hm, so it seems you aren't passing an index to the array. Can you add more info about whatself.extractor.get_input_representation(words, pos, state)
and what that returns?
– LeKhan9
Nov 12 '18 at 4:16
yes,get_input_representation
returns a np array (see edited post, hopefully made more clear)
– Matt
Nov 12 '18 at 4:19
1
You shouldn't assign it to np.array, try just creating a basic variable likeoutput_list
or something and then returning that.
– LeKhan9
Nov 12 '18 at 4:21
when i do this, i get
TypeError: list indices must be integers or slices, not list
– Matt
Nov 12 '18 at 4:04
when i do this, i get
TypeError: list indices must be integers or slices, not list
– Matt
Nov 12 '18 at 4:04
Hm, so it seems you aren't passing an index to the array. Can you add more info about what
self.extractor.get_input_representation(words, pos, state)
and what that returns?– LeKhan9
Nov 12 '18 at 4:16
Hm, so it seems you aren't passing an index to the array. Can you add more info about what
self.extractor.get_input_representation(words, pos, state)
and what that returns?– LeKhan9
Nov 12 '18 at 4:16
yes,
get_input_representation
returns a np array (see edited post, hopefully made more clear)– Matt
Nov 12 '18 at 4:19
yes,
get_input_representation
returns a np array (see edited post, hopefully made more clear)– Matt
Nov 12 '18 at 4:19
1
1
You shouldn't assign it to np.array, try just creating a basic variable like
output_list
or something and then returning that.– LeKhan9
Nov 12 '18 at 4:21
You shouldn't assign it to np.array, try just creating a basic variable like
output_list
or something and then returning that.– LeKhan9
Nov 12 '18 at 4:21
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53255750%2freshape-numpy-array-list-object-is-not-callable%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
You imported
numpy
asnp
.np.array
is a function that is used to create a numpy array (classndarray
). But you then rename thisnp.array = ...
. Now it no longer is a function, but the result of that first line. The originalnp.array
function is no longer available.– hpaulj
Nov 12 '18 at 4:18
even if
np.array
is in a different file from the caller function?– Matt
Nov 12 '18 at 4:21
Don't use a name that could confuse you or the code.
– hpaulj
Nov 12 '18 at 4:55