# Create NDArray from CSV

**URL:** <https://community.konduit.ai/t/create-ndarray-from-csv/694>\
**Category:** Uncategorized\
**Created:** [July 7, 2020, 3:01pm UTC](https://community.konduit.ai/t/create-ndarray-from-csv/694 "2020-07-07T15:01:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![salva](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/salva/32/262_2.png) [@salva](https://community.konduit.ai/u/salva)\
**Post date:** [July 7, 2020, 3:01pm UTC](https://community.konduit.ai/t/create-ndarray-from-csv/694/1 "2020-07-07T15:01:54Z")

</div>

(Question originally posted in [Gitter](https://gitter.im/deeplearning4j))

Hi, is there a simple way to read a CSV file containing numbers into a NDArray?

Anything simpler than the following Scala code?

```nohighlight
val recordReader = new CSVRecordReader(0, ',')
recordReader.initialize(new FileSplit(file))
val records = new ListBuffer[Array[Int]]()
while (recordReader.hasNext)
  records += recordReader.next.toArray.map(_.toString.toInt)
records.toArray.toNDArray

```

---

<div class="post-metadata">

**Author:** ![treo](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/treo/32/47_2.png) [@treo](https://community.konduit.ai/u/treo)\
**Post date:** [July 8, 2020, 8:16am UTC](https://community.konduit.ai/t/create-ndarray-from-csv/694/2 "2020-07-08T08:16:42Z")

</div>

Use a `RecordReaderDataSetIterator` instead, if you set the miniBatchSize to be exactly the number of rows in the CSV file, the next DataSet you get from it will have the entire file loaded in an INDArray.

Do you want to load it like that for some custom operations on it, or do you want to use it for training? Because for training you don’t actually need to load everything into an NDArray manually, you can use `RecordReaderDataSetIterator` directly.

---

<div class="post-metadata">

**Author:** ![salva](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.konduit.ai/salva/32/262_2.png) [@salva](https://community.konduit.ai/u/salva)\
**Post date:** [July 8, 2020, 8:39am UTC](https://community.konduit.ai/t/create-ndarray-from-csv/694/3 "2020-07-08T08:39:04Z")

</div>

It is a matrix representing a convolution. The number of rows or columns is not fixed and so, unknown until the full CSV has been read.
