From a text file containing three columns of data I want to be able to just take a slice of data from all three columns where the values in the first column are equal to the values defined in above. I then want to put the slice of data into a new array called slice (I am using Python 2.7)
above = range(18000, 18060, 5)
data = np.loadtxt(open('data.txt'), delimiter=None)
energies = (np.hsplit(data, 3))[0]
slice = set(energies)&set(above)
The above comes back with:
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
set(energies)&set(above)
TypeError: unhashable type: 'numpy.ndarray
Your variable
energiesprobably has the wrong shape:And that’s what happens if you read columnar data using your approach:
Probably you can simply use
instead.
(P.S. Your code looks like it’s undecided about whether it’s
dataorelementdata. I’ve assumed it’s simply a typo.)