0

I'm trying to get a Numpy array of arrays from a csv file Each row is meant to be an independent mumpy array within the general array. (relevant column names are 1,2,3....136).

I've tried this approach but I don't think it's the right way:

with open('faces_new.csv', 'r') as csvfile:
    facesreader = list(csv.DictReader(csvfile, delimiter=',', quotechar='|'))
    main_array = np.array()
    for row in facesreader:
        #create new array inside the main array
        local_array = np.array()
        for n in range(136):
            local_array = np.append(float(row[str(n)]))
            #add n to the array
        main_array = np.append(local_array)
    print(main_array)
5
  • Have you seen stackoverflow.com/questions/3518778/…? and/or stackoverflow.com/questions/25614749/…? Commented Jun 17, 2018 at 11:33
  • Yes, they are using a different data structure than mine. While I'm only using certain columns (1,2,3...136), they are using all of them, and each row is on a separate array, they are using all data. Commented Jun 17, 2018 at 11:50
  • 1
    Have you tried first doing normal list and then numpy.array()? Like in here: stackoverflow.com/a/31250215/9513536 Commented Jun 17, 2018 at 12:00
  • Definitely not the right way. np.array() raises an error. The use of np.append is all wrong too. But if you insist on working this way, stick with list and list append. Commented Jun 17, 2018 at 15:39
  • 1
    np.genfromtxt works with normal csv files. If there's something unusual about your file you need to give us a sample. Commented Jun 17, 2018 at 15:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.