NumPy 新手。
我在下面的np_2d 中创建了一个简单的二维数组。效果很好。
当然,我通常需要通过附加和/或连接现有数组来创建 Nd 数组,所以我接下来会尝试。
np.append 方法(带或不带轴参数)似乎没有做任何事情。
我尝试使用 .concantenate() 和/或简单地用 np 数组替换原始列表也失败了。
我敢肯定这是微不足道的...只是对我来说不是微不足道的 ATM。有人可以将我推向正确的方向吗?泰。
import numpy as np
# NumPy 2d array:
np_2d = np.array([[1.73, 1.68, 1.71, 1.89, 1.79], [65.4, 59.2, 63.6, 88.4, 68.7]])
print (np_2d)
# [[ 1.73 1.68 1.71 1.89 1.79]
# [65.4 59.2 63.6 88.4 68.7 ]]
print (np_2d[1]) # second list
# [65.4 59.2 63.6 88.4 68.7]
np_2d_again = np.array([1.1, 2.2, 3.3])
np.append(np_2d_again, [4.4, 5.5, 6.6])
print(np_2d_again)
# wrong: [1.1 2.2 3.3], expect [1.1 2.2 3.3], [4.4, 5.5, 6.6]
# or MAYBE [1.1 2.2 3.3, 4.4, 5.5, 6.6]
np_2d_again = np.array([[1.1, 2.2, 3.3]])
np.concatenate(np_2d_again, np.array([4.4, 5.5, 6.6]))
# Nope: TypeError: only integer scalar arrays can be converted to a scalar index
print(np_2d_again)
np_height = np.array([1.73, 1.68, 1.71, 1.89, 1.79])
np_weight = np.array([65.4, 59.2, 63.6, 88.4, 68.7])
np2_2d_again = np.array(np_height, np_weight)
# Nope: TypeError: data type not understood
height = [1.73, 1.68, 1.71, 1.89, 1.79]
weight = [65.4, 59.2, 63.6, 88.4, 68.7]
np2_2d_again = np.array(height, weight)
# Nope: TypeError: data type not understood
Helenr
相关分类