官术网_书友最值得收藏!

Matrix (2-D tensors)

Most of the structured data is represented in the form of tables or matrices. We will use a dataset called Boston House Prices, which is readily available in the Python scikit-learn machine learning library. The dataset is a numpy array consisting of 506 samples or rows and 13 features representing each sample. Torch provides a utility function called from_numpy(), which converts a numpy array into a torch tensor. The shape of the resulting tensor is 506 rows x 13 columns:

boston_tensor = torch.from_numpy(boston.data)
boston_tensor.size()

Output: torch.Size([506, 13])

boston_tensor[:2]

Output:
Columns 0 to 7
0.0063 18.0000 2.3100 0.0000 0.5380 6.5750 65.2000 4.0900
0.0273 0.0000 7.0700 0.0000 0.4690 6.4210 78.9000 4.9671

Columns 8 to 12
1.0000 296.0000 15.3000 396.9000 4.9800
2.0000 242.0000 17.8000 396.9000 9.1400
[torch.DoubleTensor of size 2x13]
主站蜘蛛池模板: 轮台县| 扶绥县| 东莞市| 英山县| 衡山县| 丁青县| 霍州市| 崇左市| 贡觉县| 墨江| 龙里县| 阜新市| 榆中县| 永安市| 万源市| 拜城县| 镇远县| 冕宁县| 阆中市| 吉隆县| 云南省| 荥经县| 武宁县| 如皋市| 衡水市| 泽普县| 佛冈县| 丁青县| 年辖:市辖区| 肇源县| 连南| 平利县| 吴旗县| 高要市| 汤原县| 民乐县| 修武县| 凤庆县| 固镇县| 旬邑县| 高安市|