Data type added as string when creating variable …array([0., 0., 0., …, 0., 0., 0.], dtype=float32)
When I change my array data type, using .astype()
or by adding to np.array(list,dtype=)
, I get an array which has a string attached. Why is this happening? (example below)
In [1]: A=[1,2,3]
In [2]: A=np.array(A,np.float32)
In [3]: A.dtype
Out[3]: dtype('float32')
In [4]: A
Out[4]: array([1., 2., 3.], dtype=float32)
In [5]: AA=[3,4,5]
In [6]: AA=np.array(AA)
In [7]: AA
Out[7]: array([3, 4, 5])
In [8]: AA.dtype
Out[8]: dtype('int32')
In [9]: AA.astype(np.float32())
Out[9]: array([3., 4., 5.], dtype=float32)
python
add a comment |
When I change my array data type, using .astype()
or by adding to np.array(list,dtype=)
, I get an array which has a string attached. Why is this happening? (example below)
In [1]: A=[1,2,3]
In [2]: A=np.array(A,np.float32)
In [3]: A.dtype
Out[3]: dtype('float32')
In [4]: A
Out[4]: array([1., 2., 3.], dtype=float32)
In [5]: AA=[3,4,5]
In [6]: AA=np.array(AA)
In [7]: AA
Out[7]: array([3, 4, 5])
In [8]: AA.dtype
Out[8]: dtype('int32')
In [9]: AA.astype(np.float32())
Out[9]: array([3., 4., 5.], dtype=float32)
python
add a comment |
When I change my array data type, using .astype()
or by adding to np.array(list,dtype=)
, I get an array which has a string attached. Why is this happening? (example below)
In [1]: A=[1,2,3]
In [2]: A=np.array(A,np.float32)
In [3]: A.dtype
Out[3]: dtype('float32')
In [4]: A
Out[4]: array([1., 2., 3.], dtype=float32)
In [5]: AA=[3,4,5]
In [6]: AA=np.array(AA)
In [7]: AA
Out[7]: array([3, 4, 5])
In [8]: AA.dtype
Out[8]: dtype('int32')
In [9]: AA.astype(np.float32())
Out[9]: array([3., 4., 5.], dtype=float32)
python
When I change my array data type, using .astype()
or by adding to np.array(list,dtype=)
, I get an array which has a string attached. Why is this happening? (example below)
In [1]: A=[1,2,3]
In [2]: A=np.array(A,np.float32)
In [3]: A.dtype
Out[3]: dtype('float32')
In [4]: A
Out[4]: array([1., 2., 3.], dtype=float32)
In [5]: AA=[3,4,5]
In [6]: AA=np.array(AA)
In [7]: AA
Out[7]: array([3, 4, 5])
In [8]: AA.dtype
Out[8]: dtype('int32')
In [9]: AA.astype(np.float32())
Out[9]: array([3., 4., 5.], dtype=float32)
python
python
edited Nov 14 '18 at 15:24
Banghua Zhao
1,2851719
1,2851719
asked Nov 14 '18 at 15:18
AJC123AJC123
63
63
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
This is not a string: dtype('float32')
. It's just one way of representing the dtype for a 32bits float.
If you had strings in your array, you would see:
dtype('S1')
or:
dtype('object')
add a comment |
You're converting your types correctly and the , dtype=float32
attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.
If you do
print(AA)
you will only see your array without any strings following.
Why does this only show up for some arrays then?
– AJC123
Nov 14 '18 at 15:39
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%2f53303430%2fdata-type-added-as-string-when-creating-variable-array0-0-0-0%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
This is not a string: dtype('float32')
. It's just one way of representing the dtype for a 32bits float.
If you had strings in your array, you would see:
dtype('S1')
or:
dtype('object')
add a comment |
This is not a string: dtype('float32')
. It's just one way of representing the dtype for a 32bits float.
If you had strings in your array, you would see:
dtype('S1')
or:
dtype('object')
add a comment |
This is not a string: dtype('float32')
. It's just one way of representing the dtype for a 32bits float.
If you had strings in your array, you would see:
dtype('S1')
or:
dtype('object')
This is not a string: dtype('float32')
. It's just one way of representing the dtype for a 32bits float.
If you had strings in your array, you would see:
dtype('S1')
or:
dtype('object')
answered Nov 14 '18 at 15:25
Matthieu BrucherMatthieu Brucher
15.8k32141
15.8k32141
add a comment |
add a comment |
You're converting your types correctly and the , dtype=float32
attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.
If you do
print(AA)
you will only see your array without any strings following.
Why does this only show up for some arrays then?
– AJC123
Nov 14 '18 at 15:39
add a comment |
You're converting your types correctly and the , dtype=float32
attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.
If you do
print(AA)
you will only see your array without any strings following.
Why does this only show up for some arrays then?
– AJC123
Nov 14 '18 at 15:39
add a comment |
You're converting your types correctly and the , dtype=float32
attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.
If you do
print(AA)
you will only see your array without any strings following.
You're converting your types correctly and the , dtype=float32
attached to your array is not an attached string but just the data type that's displayed in the representation of a Numpy array.
If you do
print(AA)
you will only see your array without any strings following.
answered Nov 14 '18 at 15:24
Tadej MagajnaTadej Magajna
1,1201332
1,1201332
Why does this only show up for some arrays then?
– AJC123
Nov 14 '18 at 15:39
add a comment |
Why does this only show up for some arrays then?
– AJC123
Nov 14 '18 at 15:39
Why does this only show up for some arrays then?
– AJC123
Nov 14 '18 at 15:39
Why does this only show up for some arrays then?
– AJC123
Nov 14 '18 at 15:39
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%2f53303430%2fdata-type-added-as-string-when-creating-variable-array0-0-0-0%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