Giả sử tôi có mảng 1x1x1x1x ... và muốn chuyển đổi nó thành vô hướng?Làm thế nào để chuyển đổi mảng singleton thành một giá trị vô hướng trong Python?
Tôi làm cách nào?
squeeze
không giúp ích gì.
import numpy as np
matrix = np.array([[1]])
s = np.squeeze(matrix)
print type(s)
print s
matrix = [[1]]
print type(s)
print s
s = 1
print type(s)
print s