История изменений
Исправление grem, (текущая версия) :
import numpy as np
a = np.array([(1,2), (3,4)], dtype={'names':['a','b'], 'formats': ['f8', 'f8']})
print("a:\n", a)
print("a.view:\n", a.view((a.dtype[0], len(a.dtype.names))) )
print("2 * a:\n", np.dot(2, a.view((a.dtype[0], len(a.dtype.names)))) )
вывод
a:
[(1.0, 2.0) (3.0, 4.0)]
a.view:
[[ 1. 2.]
[ 3. 4.]]
2 * a:
[[ 2. 4.]
[ 6. 8.]]
Исходная версия grem, :
import numpy as np
a = np.array([(1,2), (3,4)], dtype={'names':['a','b'], 'formats': ['f8', 'f8']})
print("a:\n", a)
print("a.view:\n", a.view((a.dtype[0], len(a.dtype.names))) )
b = 2 * np.ones((2, 2))
print("b:\n", b)
print("b * a:\n", np.dot(b, a.view((a.dtype[0], len(a.dtype.names)))) )
вывод
a:
[(1.0, 2.0) (3.0, 4.0)]
a.view:
[[ 1. 2.]
[ 3. 4.]]
b:
[[ 2. 2.]
[ 2. 2.]]
b * a:
[[ 8. 12.]
[ 8. 12.]]