def string_to_cols(string, ncols=1, verbose=0): """ Data is a string. Convert this to a ndarray ncols. """ data = CF.string_with_numbers_to_list(string) if ncols > 1: n = int(len(data) / ncols) data = numpy.reshape(data, (n, ncols)) # elif ncols <1: # raise ValueError("") return data
def test_string_with_exp_to_float(self): string = "1e+3, 0.5 1.2e-3" check = [1000.0, 0.5, 0.0012] res = CF.string_with_numbers_to_list(string) self.assertTrue(numpy.allclose(res, check))
def test_string_with_int_to_float(self): string = "0 1\n 2" check = [0.0, 1.0, 2.0] res = CF.string_with_numbers_to_list(string) self.assertTrue(numpy.allclose(res, check))
def test_string_with_int_spaces_enter(self): string = "0 1\n 2" check = [0, 1, 2] res = CF.string_with_numbers_to_list(string) self.assertTrue(numpy.allclose(res, check))
def test_string_with_float_spaces_enter(self): string = "0.0 1.1\n 2.2" check = [0.0, 1.1, 2.2] res = CF.string_with_numbers_to_list(string) self.assertTrue(numpy.allclose(res, check))