How to convert ndarray to autograd variable in GPU format?How do I return multiple values from a function?How do I pass a variable by reference?Proper way to declare custom exceptions in modern Python?How does Python's super() work with multiple inheritance?How to access environment variable values?How to set environment variables in PythonCatch multiple exceptions in one line (except block)“Large data” work flows using pandasHow to test multiple variables against a value?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?

Extra initial Aeneid lines in 1662 M. de Marolles version

How would you control supersoldiers in a late iron-age society?

Bash awk command with quotes

Meaning of Swimming their horses

Does a feasible high thrust high specific impulse engine exist using current non space technology?

Why are some files not movable on Windows 10?

Calculate the limit without l'Hopital rule

Ethernet, Wifi and a little human psychology

Permutations in Disguise

Teleport everything in a large zone; or teleport all living things and make a lot of equipment disappear

Does a large scratch in an ND filter affect image quality?

How to draw a Venn diagram for X - (Y intersect Z)?

What is the source of "You can achieve a lot with hate, but even more with love" (Shakespeare?)

What are the advantages and disadvantages of tail wheels that cause modern airplanes to not use them?

Why don't Wizards use wrist straps to protect against disarming charms?

Asked to Not Use Transactions and to Use A Workaround to Simulate One

How can I use expandafter the expand the definition of this control sequence?

hyperref warns when using cleveref in section

How to make classical firearms effective on space habitats despite the coriolis effect?

Can I include Abandoned Patent in CV?

How clean are pets?

Insight into cavity resonators

Expectation value of operators with non-zero Hamiltonian commutators

Why does the speed of sound decrease at high altitudes although the air density decreases?



How to convert ndarray to autograd variable in GPU format?


How do I return multiple values from a function?How do I pass a variable by reference?Proper way to declare custom exceptions in modern Python?How does Python's super() work with multiple inheritance?How to access environment variable values?How to set environment variables in PythonCatch multiple exceptions in one line (except block)“Large data” work flows using pandasHow to test multiple variables against a value?Why is “1000000000000000 in range(1000000000000001)” so fast in Python 3?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I am trying to do something like this,



data = torch.autograd.Variable(torch.from_numpy(nd_array))



It comes under the type as Variable[torch.FloatTensor], But I need Variable[torch.cuda.FloatTensor] also I want to do this in pytorch version 0.3.0 which lacks few methods like to(device) or set_default_device










share|improve this question






























    -1















    I am trying to do something like this,



    data = torch.autograd.Variable(torch.from_numpy(nd_array))



    It comes under the type as Variable[torch.FloatTensor], But I need Variable[torch.cuda.FloatTensor] also I want to do this in pytorch version 0.3.0 which lacks few methods like to(device) or set_default_device










    share|improve this question


























      -1












      -1








      -1








      I am trying to do something like this,



      data = torch.autograd.Variable(torch.from_numpy(nd_array))



      It comes under the type as Variable[torch.FloatTensor], But I need Variable[torch.cuda.FloatTensor] also I want to do this in pytorch version 0.3.0 which lacks few methods like to(device) or set_default_device










      share|improve this question














      I am trying to do something like this,



      data = torch.autograd.Variable(torch.from_numpy(nd_array))



      It comes under the type as Variable[torch.FloatTensor], But I need Variable[torch.cuda.FloatTensor] also I want to do this in pytorch version 0.3.0 which lacks few methods like to(device) or set_default_device







      python numpy gpu pytorch autograd






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 12:30









      Arjun SankarlalArjun Sankarlal

      1161 silver badge9 bronze badges




      1161 silver badge9 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1
















          You can use cuda() method of your tensor.



          If you'd like to use specific device you could go with context manager, e.g.



          with torch.cuda.device(device_index):
          t = torch.FloatTensor(1.).cuda()


          For more specific information check documentation for version 0.3.0.






          share|improve this answer
























            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/4.0/"u003ecc by-sa 4.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%2f55397711%2fhow-to-convert-ndarray-to-autograd-variable-in-gpu-format%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









            1
















            You can use cuda() method of your tensor.



            If you'd like to use specific device you could go with context manager, e.g.



            with torch.cuda.device(device_index):
            t = torch.FloatTensor(1.).cuda()


            For more specific information check documentation for version 0.3.0.






            share|improve this answer





























              1
















              You can use cuda() method of your tensor.



              If you'd like to use specific device you could go with context manager, e.g.



              with torch.cuda.device(device_index):
              t = torch.FloatTensor(1.).cuda()


              For more specific information check documentation for version 0.3.0.






              share|improve this answer



























                1














                1










                1









                You can use cuda() method of your tensor.



                If you'd like to use specific device you could go with context manager, e.g.



                with torch.cuda.device(device_index):
                t = torch.FloatTensor(1.).cuda()


                For more specific information check documentation for version 0.3.0.






                share|improve this answer













                You can use cuda() method of your tensor.



                If you'd like to use specific device you could go with context manager, e.g.



                with torch.cuda.device(device_index):
                t = torch.FloatTensor(1.).cuda()


                For more specific information check documentation for version 0.3.0.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 28 at 13:49









                Szymon MaszkeSzymon Maszke

                4,9482 gold badges7 silver badges32 bronze badges




                4,9482 gold badges7 silver badges32 bronze badges



















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















                    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%2f55397711%2fhow-to-convert-ndarray-to-autograd-variable-in-gpu-format%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

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript