我正在使用 FlatList,我想创建一个引用,以便在按下一个按钮时能够滚动 FlatList。
问题是我正在使用 Typescript,并且遇到一种我无法解决的类型错误。
问题是,如何为 FlatList 引用创建接口?
这里有一个我正在做的事情的例子。
let flatListRef = useRef();
<FlatList
ref={flatListRef} // Error Here
data={store.data}
... />
<Button
onPress={() =>
flatListRef.current.scrollToIndex({index:index})
} />
Run Code Online (Sandbox Code Playgroud)
我遇到的类型错误是当我将 ref 设置为 FlatList 时
错误说:
重载 1 of 2, '(props: FlatListProps<{ data: string; type: number; id: number; }> | Readonly<FlatListProps<{ data: string; type: number; id: number; }>>): FlatList <...>',给出了以下错误。类型“MutableRefObject”不可分配给类型“LegacyRef<FlatList<{ data: string; 类型:数字;身份证号; }>> | 不明确的'。类型“MutableRefObject”不可分配给类型“RefObject<FlatList<{ data: string; 类型:数字;身份证号; }>>'。“当前”属性的类型不兼容。类型“undefined”不可分配给类型“FlatList<{ data: string;” 类型:数字;身份证号; }> | 无效的'。
重载 2 of 2, '(props: FlatListProps<{ …
我正在尝试使用 Python 将一张图像发送到我的 Lambda 函数,只是为了测试一个项目,但 Postman 给了我一个错误,我不知道如何解决它。
\n我的代码只是检测关键“图像”中是否有一些数据并返回一些消息。我使用 Postman 发送 POST 请求,单击“正文”选项卡,选择“表单数据”选项,为密钥编写图像,并从我的计算机中选择图像文件(图像大小为 27 kb)。这是我的 Lambda 函数中的代码:
\ndef lambda_handler(event, context):\n if event['image']:\n return {\n "Message": 'Everything went ok'\n }\nRun Code Online (Sandbox Code Playgroud)\n这是我从邮递员那里收到的错误消息:
\n\n\n{ "message": "无法将请求正文解析为 json: 数值中存在意外\n字符 ('-' (代码 45)):预期数字 (0-9)\n跟随减号,为有效数值\\n在[源:\n(byte[])"----------------------------137965576541301454606184\\r\\n内容处置:表单数据;名称=“图像”;文件名=“TestImage.png”\\r\\n内容类型:\nimage/png\\r\\n\\r\\n\xef\xbf\xbdPNG\\r\\n\\n ... }
\n
我正在学习 sklearn,但我不太明白其中的区别以及为什么将 4 个输出与函数 train_test_split 一起使用。
在文档中,我找到了一些示例,但这还不足以结束我的疑虑。
代码是使用 x_train 来预测 x_test 还是使用 x_train 来预测 y_test?
训练和测试有什么区别?我是否使用 train 来预测测试或类似的东西?
我很困惑。我将在文档中提供以下示例。
>>> import numpy as np
>>> from sklearn.model_selection import train_test_split
>>> X, y = np.arange(10).reshape((5, 2)), range(5)
>>> X
array([[0, 1],
[2, 3],
[4, 5],
[6, 7],
[8, 9]])
>>> list(y)
[0, 1, 2, 3, 4]
>>> X_train, X_test, y_train, y_test = train_test_split(
... X, y, test_size=0.33, random_state=42)
...
>>> X_train
array([[4, 5],
[0, 1],
[6, 7]])
>>> y_train
[2, 0, …Run Code Online (Sandbox Code Playgroud) python machine-learning scikit-learn supervised-learning sklearn-pandas
python ×2
aws-lambda ×1
react-hooks ×1
react-native ×1
reactjs ×1
scikit-learn ×1
typescript ×1