0

After looking through some other questions I can't seem to find a solution for my code. what is causing "too many indices for an array"

I have followed the steps of this question to get to this point, where x = training[:,1] gives me the error.

How to access the ith column of a NumPy multidimensional array?

import numpy as np

csv = np.genfromtxt('admission_predict.csv', delimiter=',', names=True)
training = csv[:300] #first 300 lines
testing = csv[300:] #last 100 lines 

x = training[:,1]
print(x)
Engineero
  • 12,340
  • 5
  • 53
  • 75
Wise
  • 69
  • 7
  • 1
    You have a 1D array, you are accessing it like a 2D array. What are you trying to do with `x = training[:,1]?` – user3483203 Apr 08 '19 at 15:35
  • You tell us. What line is causing the error? Should say in your error traceback. What does your data look like? You haven't provided enough information here for anybody to help you. – Engineero Apr 08 '19 at 15:36
  • later in the program I use it as an x value for a matplotlib scatter plot, so I need a bunch of values from the first column of the excel file, not all of the data from each row. @user3483203 – Wise Apr 08 '19 at 15:37
  • @Engineero x = training[:,1] causes the error. – Wise Apr 08 '19 at 15:38
  • 1
    By specifying `names=True` you tell `genfromtxt` to make a structured array. Look at `csv.shape` and `csv.dtype`. If you want a 2d array, use `skip_header` instead. Alternatively access `x` by field name: `x=csv['f1']` – hpaulj Apr 08 '19 at 17:06

0 Answers0