# DataFrame.tensor

danfo.DataFrame.**tensor**

> **Note:** [Tensorflow](https://js.tensorflow.org/api/latest/#tensor) tensors have single dtype, and will replace any string value with NaN. Use with care.

## **Examples**

{% tabs %}
{% tab title="Node" %}

```javascript
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()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
float32

Tensor {
  kept: false,
  isDisposedInternal: false,
  shape: [ 4, 3 ],
  dtype: 'float32',
  size: 12,
  strides: [ 3 ],
  dataId: {},
  id: 0,
  rankType: '2'
}

Tensor
    [[-20       , 34, 20],
     [30        , -4, 20],
     [47.2999992, 5 , 30],
     [-20       , 6 , 30]]
```

{% endtab %}
{% endtabs %}

String values in a Tensor are represented as NaN, so ensure to transform them before working with tensor representations.

{% tabs %}
{% tab title="Node" %}

```javascript
const dfd = require("danfojs-node")

let data = { "Abs": [20.2, 30, 47.3] ,
             "Count": [34, 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()
```

{% endtab %}

{% tab title="Browser" %}

```
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Output" %}

```
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]]
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://danfo.jsdata.org/api-reference/dataframe/dataframe.tensor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
