how to import datafile using numpy ?
i did the following :
import numpy as n
filename='data_file.txt'
data=n.loadtxt('data_file.txt')

but it is bot working ?

Hey !
What error are you getting ??
I just tried it out on Python 2.7.10
However i did notice you are not using the filename var, when loading?

import numpy as n
filename='myfile.txt'
data=n.loadtxt(filename)
print data
[ 2.35000000e+02 5.43000000e+02 5.43000000e+02 5.44345000e+05]

The way you wrote the code snippet, it works only if data_file.txt is in the current working directory. A solution is to use the full path to the data file. If the data file is in the same directory as the python script, you can also use

import os
filename = os.path.join(os.path.dirname(__file__), 'data_file.txt')

But as Rasmus_2 said before, we'd like to see the full error traceback that python sends, as well as your version of python.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.