I am trying to load data from csv by row, then create 2d array out of each row and store it inside array:
loading:
with open('data_more.csv', newline='') as csvfile:
data = list(csv.reader(csvfile))
parsing:
def getTrainingData():
label_data = []
for i in range( 0 , len(data) - 1):
y = list(data[i][1:41:1])
y = list(map(lambda x: list(map(lambda z: int(z),x)),y))
y = create2Darray(y)
label_data.append(y)
labelY = np.array(label_data,dtype=float)
create2Darray func:
def create2Darray( arr ):
final_arr = []
index = 0
while( index < len(arr)):
temp = arr[index:index+4:1]
final_arr.append(temp)
index+=4
return final_arr
This is simple task, yet i keep recieving erro:
ValueError: setting an array element with a sequence.
I have read that its related to situation when the shape of elements isnt same. However when i print shape of all elements inside labelY it outputs same shape.
What is causing this problem then? The problem occurs on this line
labelY = np.array(label_data,dtype=float)
my csv has format
number, number, number
basicly N numbers in row separated by "," example thanks for help.
datalook like?np.genfromtxt?pandasto read thecsvand perform operations and then using thelocandilocto slice them intoseriesthat'll directly convert tonp.array. You can also use the.dropna()to drop any value that isNoneType