Python numpy savetxt

Давайте посмотрим, могли ли мы стать ближе к ядру проблемы:

, Если Вы запускаете свою программу (позволяет, говорят), 1000 использований x запускаются (), тогда 1000 x использование выполненного () в потоке, действительно оба освободите память? Если так, тогда Ваш алгоритм должен быть проверен (т.е. на внешние объекты, такие как Векторы, используемые в Вашем Выполнимом).

, Если нет такой утечки памяти, как описано выше тогда Вас, должен заняться расследованиями о стартовых параметрах и использовании памяти потоков относительно JVM.

5
задан astrofrog 9 October 2009 в 16:56
поделиться

3 ответа

You need to construct you array differently:

z = np.array(zip([1,2,3,4,5], ['a','b','c','d','e']), dtype=[('int', int), ('str', '|S1')])
np.savetxt('test.txt', z, fmt='%i %s')

when you're passing a sequence, savetext performs asarray(sequence) call and resulting array is of type |S4, that is all elements are strings! that's why you see this error.

12
ответ дан 18 December 2019 в 09:50
поделиться

If you want to save a CSV file you can also use the function rec2csv (included in matplotlib.mlab)

>>> from matplotlib.mlab import rec2csv
>>> rec = array([(1.0, 2), (3.0, 4)], dtype=[('x', float), ('y', int)])
>>> rec = array(zip([1,2,3,4,5], ['a','b','c','d','e']), dtype=[('x', int), ('y', str)])
>>> rec2csv(rec, 'recordfile.txt', delimiter=' ')

hopefully, one day pylab's developers will implement a decent support to writing csv files.

4
ответ дан 18 December 2019 в 09:50
поделиться

I think the problem you are having is that you are passing tuples through the formating string and it can't interpret the tuple with %i. Try using fmt="%s", assuming this is what you are looking for as the output:

1 a
2 b
3 c
4 d
5 e
1
ответ дан 18 December 2019 в 09:50
поделиться
Другие вопросы по тегам:

Похожие вопросы: