How would I be able to print the last value of element_val numpy arrays. It is the second index of [ 2. 2. 30.] which is 30. So the values will go like 30,40,50...670,680. How would I be able to do that since the numpy array is 1 dimensional?
input.csv file:
element,LNPT,SNPT,NLP,NSP,TNT,TPnL,MxPnL,MnPnL,MxU,MxD
[ 2. 2. 30.],0,0,4,4,8,-0.1,-0.0,-0.1,17127,-3
[ 2. 2. 40.],0,0,2,2,4,0.0,-0.0,-0.0,17141,-3
[ 2. 2. 50.],0,0,2,2,4,0.0,-0.0,-0.0,17139,-3
[ 2. 2. 60.],2,0,6,6,12,0.5,2.3,-1.9,17015,-3
[ 2. 2. 70.],1,0,4,4,8,0.3,0.3,-0.0,17011,-3
Code:
import numpy as np
import pandas as pd
my_data = pd.read_csv('input.csv').to_numpy()
element_vals = my_data[:,0]
print(element_vals)
Output:
['[ 2. 2. 30.]' '[ 2. 2. 40.]' '[ 2. 2. 50.]' ... '[ 6. 7.5 660. ]'
'[ 6. 7.5 670. ]' '[ 6. 7.5 680. ]']
printed an array to a file, rather than actually writing CSV, then tried to read the file as CSV anyway.printshould never be used as a way of saving NumPy array data. It discards data by default, and it's awkward to parse even when it doesn't discard data. Usenumpy.saveandnumpy.load, ornumpy.savetxtandnumpy.loadtxt.printed a number of arrays individually, possiblyprinting each row of a 2D array. Either way, it's a bad idea, andpandas.read_csvis the wrong tool to read this.)element_valshas probably lost the first data row, sinceread_csvprobably interpreted it as a column header.[ 2. 2. 30.]values get outputted asnanwhen I usegenfromtxthence why I used pandas. I have updated to show what the issue to show whatinput.csvlooks like.