The problem is that, although you do not mention it, you must be using Python 3.x but you use a proprietary method of Python 2.x. You must open the file in text mode, not in binary mode, as you are doing now. On the other hand you must specify the newline
parameter giving it an empty string so that it does not create a new default line between each row of the matrix. The code must be:
import csv
import numpy as np
tabla = np.random.random((3000,14))
with open('tabla.csv', 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerows(tabla)
For more information, here is the link to the official documentation of the csv module in Python 3
Edit:
Responding to the comment on how to add titles to the csv columns, keep in mind that a csv does not have headers intrinsically, it is simply that, a file with data separated by commas. What is done is to use the first line of the CSV for the headers. To do this we simply add an initial row just created the csv and before saving the remaining rows:
import csv
tabla = [[1,2,3],
[4,5,6],
[7,8,9]]
headers = ('Imagen', 'Distorsión', 'Nivel')
with open('tabla.csv', 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(headers)
writer.writerows(tabla)
At the time of reading the data we simply specify that the first line contains the names (some libraries are already trying to do this by default), for example using DictReader
of the same library we can load the data and access by the name of the columns:
with open('tabla.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row['Imagen'])
We print the first column (called 'Image'):
1
4
7