Getting a price array












0















In the current moment, I have a tensor ytrue with ytrue.shape equal to (4650, 30, 161).



I am taking information every 5 seconds on the NYSE for a specific stock between 9:00 AM and 4:30 PM. So I have 4650 layers in the tensor which represent each 5 seconds during that period. Each layer has dimension (30, 161). 30 represents the number of steps I look in the past and 161 represents how many features (160 features + the price as the target).



I tried to reshape it the get the current price with



X = ytrue[:, :, -1]


but I got



ipdb> X                                                                                                                                     
array([[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ],
[262.605, 261.99 , 261.99 , ..., 263.75 , 263.75 , 263.71 ],
[261.99 , 261.99 , 262.015, ..., 263.75 , 263.71 , 263.63 ],
...,
[253.065, 253.03 , 252.93 , ..., 253.115, 253.18 , 253.27 ],
[253.03 , 252.93 , 253.1 , ..., 253.18 , 253.27 , 253.345],
[252.93 , 253.1 , 253.145, ..., 253.27 , 253.345, 253.35 ]])


I need to take the last element of each subarray to create an array of prices, e.g.



[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ] --> 263.75


How can I get an array of each of those elements from ytrue?










share|improve this question




















  • 2





    ytrue[:, -1, -1]?

    – Divakar
    Nov 20 '18 at 17:16
















0















In the current moment, I have a tensor ytrue with ytrue.shape equal to (4650, 30, 161).



I am taking information every 5 seconds on the NYSE for a specific stock between 9:00 AM and 4:30 PM. So I have 4650 layers in the tensor which represent each 5 seconds during that period. Each layer has dimension (30, 161). 30 represents the number of steps I look in the past and 161 represents how many features (160 features + the price as the target).



I tried to reshape it the get the current price with



X = ytrue[:, :, -1]


but I got



ipdb> X                                                                                                                                     
array([[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ],
[262.605, 261.99 , 261.99 , ..., 263.75 , 263.75 , 263.71 ],
[261.99 , 261.99 , 262.015, ..., 263.75 , 263.71 , 263.63 ],
...,
[253.065, 253.03 , 252.93 , ..., 253.115, 253.18 , 253.27 ],
[253.03 , 252.93 , 253.1 , ..., 253.18 , 253.27 , 253.345],
[252.93 , 253.1 , 253.145, ..., 253.27 , 253.345, 253.35 ]])


I need to take the last element of each subarray to create an array of prices, e.g.



[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ] --> 263.75


How can I get an array of each of those elements from ytrue?










share|improve this question




















  • 2





    ytrue[:, -1, -1]?

    – Divakar
    Nov 20 '18 at 17:16














0












0








0








In the current moment, I have a tensor ytrue with ytrue.shape equal to (4650, 30, 161).



I am taking information every 5 seconds on the NYSE for a specific stock between 9:00 AM and 4:30 PM. So I have 4650 layers in the tensor which represent each 5 seconds during that period. Each layer has dimension (30, 161). 30 represents the number of steps I look in the past and 161 represents how many features (160 features + the price as the target).



I tried to reshape it the get the current price with



X = ytrue[:, :, -1]


but I got



ipdb> X                                                                                                                                     
array([[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ],
[262.605, 261.99 , 261.99 , ..., 263.75 , 263.75 , 263.71 ],
[261.99 , 261.99 , 262.015, ..., 263.75 , 263.71 , 263.63 ],
...,
[253.065, 253.03 , 252.93 , ..., 253.115, 253.18 , 253.27 ],
[253.03 , 252.93 , 253.1 , ..., 253.18 , 253.27 , 253.345],
[252.93 , 253.1 , 253.145, ..., 253.27 , 253.345, 253.35 ]])


I need to take the last element of each subarray to create an array of prices, e.g.



[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ] --> 263.75


How can I get an array of each of those elements from ytrue?










share|improve this question
















In the current moment, I have a tensor ytrue with ytrue.shape equal to (4650, 30, 161).



I am taking information every 5 seconds on the NYSE for a specific stock between 9:00 AM and 4:30 PM. So I have 4650 layers in the tensor which represent each 5 seconds during that period. Each layer has dimension (30, 161). 30 represents the number of steps I look in the past and 161 represents how many features (160 features + the price as the target).



I tried to reshape it the get the current price with



X = ytrue[:, :, -1]


but I got



ipdb> X                                                                                                                                     
array([[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ],
[262.605, 261.99 , 261.99 , ..., 263.75 , 263.75 , 263.71 ],
[261.99 , 261.99 , 262.015, ..., 263.75 , 263.71 , 263.63 ],
...,
[253.065, 253.03 , 252.93 , ..., 253.115, 253.18 , 253.27 ],
[253.03 , 252.93 , 253.1 , ..., 253.18 , 253.27 , 253.345],
[252.93 , 253.1 , 253.145, ..., 253.27 , 253.345, 253.35 ]])


I need to take the last element of each subarray to create an array of prices, e.g.



[262.655, 262.605, 261.99 , ..., 263.615, 263.75 , 263.75 ] --> 263.75


How can I get an array of each of those elements from ytrue?







python numpy indexing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 17:12







user1050421

















asked Nov 20 '18 at 17:02









user1050421user1050421

177




177








  • 2





    ytrue[:, -1, -1]?

    – Divakar
    Nov 20 '18 at 17:16














  • 2





    ytrue[:, -1, -1]?

    – Divakar
    Nov 20 '18 at 17:16








2




2





ytrue[:, -1, -1]?

– Divakar
Nov 20 '18 at 17:16





ytrue[:, -1, -1]?

– Divakar
Nov 20 '18 at 17:16












1 Answer
1






active

oldest

votes


















2














Use fancy indexing.



X[:, -1] should do the trick.



A smaller example you can easily eyeball:



In [4]: x = np.arange(25).reshape(5, 5)

In [5]: x
Out[5]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])

In [6]: x[:, -1]
Out[6]: array([ 4, 9, 14, 19, 24])


HTH.






share|improve this answer


























  • I think X[:, -1] should still work. I've got to run, but I'll check back later...

    – Matt Messersmith
    Nov 20 '18 at 17:14











  • Sorry, I made a mistake in my question. X is already equal to ytrue[:, :, -1]. So I guess X has to be equal to ytrue[:, :, -1] [:, -1]?

    – user1050421
    Nov 20 '18 at 17:16











  • Yes, that works. You could also just do it in two steps with X as a temp. Alternatively I believe ytrue[:, -1,-1] will work if you want it all on one slice.

    – Matt Messersmith
    Nov 20 '18 at 17:59











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397983%2fgetting-a-price-array%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









2














Use fancy indexing.



X[:, -1] should do the trick.



A smaller example you can easily eyeball:



In [4]: x = np.arange(25).reshape(5, 5)

In [5]: x
Out[5]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])

In [6]: x[:, -1]
Out[6]: array([ 4, 9, 14, 19, 24])


HTH.






share|improve this answer


























  • I think X[:, -1] should still work. I've got to run, but I'll check back later...

    – Matt Messersmith
    Nov 20 '18 at 17:14











  • Sorry, I made a mistake in my question. X is already equal to ytrue[:, :, -1]. So I guess X has to be equal to ytrue[:, :, -1] [:, -1]?

    – user1050421
    Nov 20 '18 at 17:16











  • Yes, that works. You could also just do it in two steps with X as a temp. Alternatively I believe ytrue[:, -1,-1] will work if you want it all on one slice.

    – Matt Messersmith
    Nov 20 '18 at 17:59
















2














Use fancy indexing.



X[:, -1] should do the trick.



A smaller example you can easily eyeball:



In [4]: x = np.arange(25).reshape(5, 5)

In [5]: x
Out[5]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])

In [6]: x[:, -1]
Out[6]: array([ 4, 9, 14, 19, 24])


HTH.






share|improve this answer


























  • I think X[:, -1] should still work. I've got to run, but I'll check back later...

    – Matt Messersmith
    Nov 20 '18 at 17:14











  • Sorry, I made a mistake in my question. X is already equal to ytrue[:, :, -1]. So I guess X has to be equal to ytrue[:, :, -1] [:, -1]?

    – user1050421
    Nov 20 '18 at 17:16











  • Yes, that works. You could also just do it in two steps with X as a temp. Alternatively I believe ytrue[:, -1,-1] will work if you want it all on one slice.

    – Matt Messersmith
    Nov 20 '18 at 17:59














2












2








2







Use fancy indexing.



X[:, -1] should do the trick.



A smaller example you can easily eyeball:



In [4]: x = np.arange(25).reshape(5, 5)

In [5]: x
Out[5]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])

In [6]: x[:, -1]
Out[6]: array([ 4, 9, 14, 19, 24])


HTH.






share|improve this answer















Use fancy indexing.



X[:, -1] should do the trick.



A smaller example you can easily eyeball:



In [4]: x = np.arange(25).reshape(5, 5)

In [5]: x
Out[5]:
array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24]])

In [6]: x[:, -1]
Out[6]: array([ 4, 9, 14, 19, 24])


HTH.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 17:12

























answered Nov 20 '18 at 17:08









Matt MessersmithMatt Messersmith

5,98921730




5,98921730













  • I think X[:, -1] should still work. I've got to run, but I'll check back later...

    – Matt Messersmith
    Nov 20 '18 at 17:14











  • Sorry, I made a mistake in my question. X is already equal to ytrue[:, :, -1]. So I guess X has to be equal to ytrue[:, :, -1] [:, -1]?

    – user1050421
    Nov 20 '18 at 17:16











  • Yes, that works. You could also just do it in two steps with X as a temp. Alternatively I believe ytrue[:, -1,-1] will work if you want it all on one slice.

    – Matt Messersmith
    Nov 20 '18 at 17:59



















  • I think X[:, -1] should still work. I've got to run, but I'll check back later...

    – Matt Messersmith
    Nov 20 '18 at 17:14











  • Sorry, I made a mistake in my question. X is already equal to ytrue[:, :, -1]. So I guess X has to be equal to ytrue[:, :, -1] [:, -1]?

    – user1050421
    Nov 20 '18 at 17:16











  • Yes, that works. You could also just do it in two steps with X as a temp. Alternatively I believe ytrue[:, -1,-1] will work if you want it all on one slice.

    – Matt Messersmith
    Nov 20 '18 at 17:59

















I think X[:, -1] should still work. I've got to run, but I'll check back later...

– Matt Messersmith
Nov 20 '18 at 17:14





I think X[:, -1] should still work. I've got to run, but I'll check back later...

– Matt Messersmith
Nov 20 '18 at 17:14













Sorry, I made a mistake in my question. X is already equal to ytrue[:, :, -1]. So I guess X has to be equal to ytrue[:, :, -1] [:, -1]?

– user1050421
Nov 20 '18 at 17:16





Sorry, I made a mistake in my question. X is already equal to ytrue[:, :, -1]. So I guess X has to be equal to ytrue[:, :, -1] [:, -1]?

– user1050421
Nov 20 '18 at 17:16













Yes, that works. You could also just do it in two steps with X as a temp. Alternatively I believe ytrue[:, -1,-1] will work if you want it all on one slice.

– Matt Messersmith
Nov 20 '18 at 17:59





Yes, that works. You could also just do it in two steps with X as a temp. Alternatively I believe ytrue[:, -1,-1] will work if you want it all on one slice.

– Matt Messersmith
Nov 20 '18 at 17:59


















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397983%2fgetting-a-price-array%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy