0

Is there any way to turn a list of strings into a numpy.ndarray?. Because I tried this code:

All  = np.ndarray([str(necessary_lines).split(',')])

Which gives this error:

Traceback (most recent call last):
  File "/Users/username/Desktop/Coding/Python/somePythonProgram.py", line 47, in <module>
    print(parseCSV(file))
  File "/Users/username/Desktop/Coding/Python/somePythonProgram.py", line 34, in somePythonProgram
    All  = np.ndarray([str(necessary_lines).split(',')])
TypeError: 'list' object cannot be interpreted as an integer

Or is it that you can't turn a list of strings into a numpy array?

5
  • 1
    What is your necessary_lines? Commented Jun 16, 2020 at 17:19
  • Why the [,] in [str(necessary_lines).split(',')]? .split() already returns a list, you don't need to stick it into another. In any event, please provide a minimal reproducible example. We shouldn't need to guess about what your data is. Commented Jun 16, 2020 at 17:21
  • Necessary_lines is a list of filtered lines of a CSV document (filtered as in the blank lines are removed). But then I want the csv values themself, seperated in their own array(to represent each line). Commented Jun 16, 2020 at 17:24
  • Also -- your traceback doesn't match your posted code. Commented Jun 16, 2020 at 17:25
  • Oh yeah, I removed some stuff Commented Jun 16, 2020 at 17:26

1 Answer 1

2

You should use np.array instead of np.ndarray. Check out the link. Also, you can use np.asarray().

Sign up to request clarification or add additional context in comments.

2 Comments

If my answer solver your first problem, please upvote and then post your new problem.
Don't worry, I finished the program. It's now working perfectly. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.