Hello! Welcome back to our tutorial.
Today we will learn how to create array in tensorflow.
What is tensorflow?
Tensorflow is open source platform for machine learning. It has comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-art in ML and developing easily build and deploy ML powered applications.
How to import Tensorflow?
import tensorflow as tf
import numpy as np
How to create array in tensorflow?
We have 2 methods to create array in tensorflow:-
- Using tensorflow inbuilt function
- Using numpy
Let us understand it one by one.
1. Using Tensorflow's inbuilt function
We can create array in tensorflow using tensorflow's inbuilt function i.e. constant
arr = tf.constant([1,2,3,4,5])
Let us understand by code:-
What is constant?
constant is useful for asserting that the value can be embedded that way. If the argument dtype is not specified, then the type is inferred from the type of value
2. Using Numpy array
Yes, you can create tensors using Numpy array. First you have to create array using numpy and then convert it to tensors using TensorfLow.
tf.convert_to_tensor(array_name)
Let us understand by Code:-
You can do all numpy operation and just convert it to tensors using
arr = tf.convert_to_tensor(array_name)
I hope you would like the post and enjoyed.
Please Subscribe to our YouTube channel - Codin India
Comments
Post a Comment