danfo.DataFrame.tensor [source]
Returns:
return tf.tensor
Note: Tensorflow tensors have single dtype (mainly float32), and will replace any string value with NaN. Use with care.
const dfd = require("danfojs-node")​let data = { "A": [-20, 30, 47.3, -20] ,"B": [34, -4, 5, 6] ,"C": [20, 20, 30, 30]}let df = new dfd.DataFrame(data)let tf_tensor = df.tensor​console.log(tf_tensor.dtype);​console.log(tf_tensor);​tf_tensor.print()
​
float32​Tensor {kept: false,isDisposedInternal: false,shape: [ 3, 3 ],dtype: 'float32',size: 9,strides: [ 3 ],dataId: {},id: 0,rankType: '2'}​Tensor[[-20 , 34, 20],[30 , -4, 2 ],[47.2999992, 5 , 30]]
String values in a Tensor are represented as NaN, so ensure to transform them before working with tensor representations.
const dfd = require("danfojs-node")​let data = { "Abs": [20.2, 30, 47.3] ,"Count": [34, 4, 5, 6] ,"country code": ["NG", "FR", "GH"] }​​let df = new dfd.DataFrame(data)let tf_tensor = df.tensor​console.log(tf_tensor.dtype);​console.log(tf_tensor);​tf_tensor.print()
​
float32​Tensor {kept: false,isDisposedInternal: false,shape: [ 3, 3 ],dtype: 'float32',size: 9,strides: [ 3 ],dataId: {},id: 0,rankType: '2'}​Tensor[[20.2000008, 34, NaN],[30 , 4 , NaN],[47.2999992, 5 , NaN]]