0

enter image description here

I have 256 x 8 text file, i want to fetch it into np array(256,8), with int cast

    import numpy as np
    import cv2.cv2 as cv2
    import math
    import matplotlib.pyplot as plt

np.loadtxt(fname='data.txt')

then i get this error: could not convert string to float: '200.35,159.32,200.35,113.74,245.48,113.74,245.48,159.32'

1
  • 1
    The default delimiter in loadtxt is white space, not comma. Commented Dec 3, 2019 at 23:45

1 Answer 1

3

You need to split the strings into its separate values. loadtxt has a parameter that does this:

np.loadtxt(fname='data.txt', delimiter=',')

This splits each row at the comma so that each number can be read as a separate value.

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

1 Comment

Welcome to Stack Overflow! As a suggestion, consider linking to the relevant docs so that users can see up-to-date information about the keyword args and know where to find information later :)

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.