About this question
How to convert tensor to numpy array when using Tensorflow with Python bindings?
How to convert tensor to numpy array when using Tensorflow with Python bindings?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Data Science Expert
Answered on Apr 14, 2021
For your problem, Tensor returned by Session.run() or tf.eval() is already a NumPy array, except for Sparse tensor, they return Sparse value.
For example:
>>> print(type(tf.Session().run(tf.constant([1,2,3]))))
Or
>>> sess = tf.InteractiveSession()
>>> print(type(tf.constant([1,2,3]).eval()))
Or
>>> sess = tf.Session()
>>> with sess.as_default():
>>> print(type(tf.constant([1,2,3]).eval()))
Hope this answer helps you convert tensor to NumPy array.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Step-by-step Data Science guides from industry experts
Common Data Science interview questions, answered
Guides, tips and career advice on Data Science from JanBask experts.
Data Science The Best Data Science Projects (Beginner To Advanced)
Discover 15 data science project ideas from beginner to advanced levels. Includes tech stacks, time estimates, & real-use cases.…
Data Science Data Science vs Software Engineering - What you should know?
Compare Data Science vs. Software Engineering - explore skills, tools, roles, salaries, and career scope. Discover which tech…
Data Science Top 15 Deep Learning Algorithms You Must Know in 2025
Discover the top 15 deep learning algorithms powering AI in 2025. Learn how deep learning models, DL models, and deep machine…
Data Science Deep Learning Tutorial Guide for Beginners
Deep Learning, Machine Learning & Artificial Intelligence have become trending words of the IT sector today.