Re: [Numpy-discussion] dtype and pep3118

2011-11-23 Thread Pauli Virtanen
23.11.2011 15:01, Fabrice Silva kirjoitti:
 Hi folks,
 how should I specify a PEP3118 buffer format that could be understand by
 numpy as the following dtype:
 
 dtype = [('t11', '|f8'), ('t22', '|f8'), ('t33', '|f8'),
  ('t23', '|f8'), ('t13', '|f8'), ('t12', '|f8')]
 
 so that I can manipulate a structured array and its fields ?
 
 I tried strings like
 T{d:t11: d:t22: d:t33: d:t23: d:t13: d:t12:}:Tensor2d:
 d:t11: d:t22: d:t33: d:t23: d:t13: d:t12:
 
 without success

 dtype = [('t11', '|f8'), ('t22', '|f8'), ('t33', '|f8'),
...  ('t23', '|f8'), ('t13', '|f8'), ('t12', '|f8')]
 x = np.zeros([1], dtype=dtype)
 memoryview(x).format
'T{d:t11:d:t22:d:t33:d:t23:d:t13:d:t12:}'
 np.array(memoryview(x))
array([(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)],
  dtype=[('t11', 'f8'), ('t22', 'f8'), ('t33', 'f8'), ('t23',
'f8'), ('t13', 'f8'), ('t12', 'f8')])

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] dtype and pep3118

2011-11-23 Thread Fabrice Silva
Le mercredi 23 novembre 2011 à 15:52 +0100, Pauli Virtanen a écrit :
 
  dtype = [('t11', '|f8'), ('t22', '|f8'), ('t33', '|f8'),
 ...  ('t23', '|f8'), ('t13', '|f8'), ('t12', '|f8')]
  x = np.zeros([1], dtype=dtype)
  memoryview(x).format
 'T{d:t11:d:t22:d:t33:d:t23:d:t13:d:t12:}'
  np.array(memoryview(x))
 array([(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)],
   dtype=[('t11', 'f8'), ('t22', 'f8'), ('t33', 'f8'), ('t23',
 'f8'), ('t13', 'f8'), ('t12', 'f8')])

Thanks!

-- 
Fabrice Silva

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion