0

I would like to import just one value from a csv file. So far, I have been succesfull at using the skip_header and skip_footer options to seek out this element. It is a float value. One problem though, when I try to use this one element from my array, I get an error. Example:

import numpy as np
x = np.genfromtxt('junker.txt',skip_header=6,skip_footer=7)
print x

returns

array(10)

however

print x[0]

returns

TypeError: len() of unsized object

I just want to be able to use this value however I cannot because it's in a numpy array. Please help

handroski
  • 81
  • 2
  • 3
  • 15

1 Answers1

1

a numpy array in that form is actually just a number. For example:

x = np.array([1])

Has a length of 1. However your array does not. Being just a number, you may utilize it right away! Example

x = np.array(3)
y = x + 3
print y

Will yield 3.

The length of x will yield an error because while this is an array, it is technically a zero dimensional array. Hence a length cannot be recovered from this variable.

handroski
  • 81
  • 2
  • 3
  • 15