I have quickly skimmed your code and noticed the following things, You are reading a text file and splitting with "," I think you should be using
CSV file instead of .txt file which will be easier for processing.
Since you didn't specify what you are trying to achieve in this code I made few assumptions.
I see some words like DataFile, Data, etc., so I guess you are performing some data analysis, In that case you should go for pandas to read the data frames rather processing it on your own since there are various other concerns like pre-processing etc.
Here is an example file of yours,
DataFile:
data1.txt
1,2,3,4
I have converted this into csv named
data.csv
Here is the code:
import pandas as pd
import numpy as np
if __name__ == "__main__":
data_frame = pd.read_csv("data.csv", header=None)
np_array = data_frame.iloc[:, :].values
print(np_array)
print(np_array.ndim)
which will output this,
[[1 2 3 4]]
2 => dimension
Refere more here:
numpy.ndarray.ndim — NumPy v1.13 Manual[
^]
And one more thing, numpy has a method named "reshape" which can reshape the array for the dimensions you want.