title: taking csv information, sorting and producing numpy array (python
body: <p>I'm trying to define a function that takes two inputs, instructions and actions for a car, which are lists of strings that contain the name of the CSV files to be opened that contain data (I cannot use the csv library import). The csv files contain data in columns in the format; action, time, speed. e.g N, 10, 10 means North for 10 seconds at 10 meters per second. the displacement would then be 100 north etc.</p>
  
  <p>Say the first instr1.csv file contains (no header):</p>
  
  <pre><code>N, 10, 10 
  E, 10, 8 
  S, 10, 5
  W, 10, 4
  </code></pre>
  
  <p>Ultimately I want to return the vertical and horizontal displacements for the car and then the total distance in numpy arrays. I keep getting stuck trying to figure out how when the action is North, I take the 2nd column and 3rd column, multiply them by each other, append it to a list and then create a numpy list to be returned.</p>
  
  <p>First I read the data, loops over each row to produce data, then create a structured array (arrayInstructionsFile1) with dtypes. </p>
  
  <p>What I've got so far is:</p>
  
  <pre><code>import numpy as np
  #import matplotlib.pyplot as plt #(plot numpy arrays later)
  
  
  def car(instructions,actions):
  
      instrucFile = instructions
      newArrayFile1 = []
      newArrayFile2 = []
      lstNorth = []
  
      for file in instrucFile[0:1]:    #reads first csv file
          with open(file) as filedata: #get data
              arrayInstructionsFile1 = np.genfromtxt(file,delimiter=',',dtype=[('action','U1'),('time',float),('speed',float)],encoding=None,usecols=None)
              for i in arrayInstructionsFile1:      #loops each row to a list
                  newArrayFile1.append(i)
              npArrInstrucDataFile1 = np.array(newArrayFile1) #prints structured array
  
      print('File1 structured array = ',npArrInstrucDataFile1)
  </code></pre>
  
  <p>now using the function like this:</p>
  
  <pre><code>car(['instr1.csv','instr2.csv'],['act1.csv','act2.csv'])
  </code></pre>
  
  <p>gives the structured array:</p>
  
  <pre><code>File1 structured array =  [('N', 10., 10.) ('E', 10.,  8.) ('S', 10.,  5.) ('W', 10.,  4.)]
  </code></pre>
  
  <p>but I'm confused, how do I tell python to put the values into a new array depending on whether the action is N,E,S or W, and then multiply the floats by each other so I can return the required numpy arrays?</p>
  
  <p>as you can see I am struggling greatly with this, so any help/guidance or perhaps even suggesting a better approach would be very very appreciated. I have tried to explain everything i'm trying to do to avoid confusion, sorry if it's a bit long!</p>
  
  <p>Thank you!</p>