Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Zheng Gaoshan
co-devTest
Commits
760c1f75
Commit
760c1f75
authored
May 19, 2025
by
Zheng Gaoshan
Browse files
提交代码
parent
5d8128f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
test.py
0 → 100644
View file @
760c1f75
import
numpy
as
np
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
from
sklearn.linear_model
import
LinearRegression
# 确保正确导入
import
torch
def
test_numpy
():
print
(
"Testing NumPy..."
)
a
=
np
.
array
([
1
,
2
,
3
])
b
=
np
.
array
([
4
,
5
,
6
])
c
=
a
+
b
print
(
"NumPy array sum:"
,
c
)
def
test_pandas
():
print
(
"
\n
Testing Pandas..."
)
data
=
{
'Name'
:
[
'Alice'
,
'Bob'
,
'Charlie'
],
'Age'
:
[
25
,
30
,
35
]}
df
=
pd
.
DataFrame
(
data
)
print
(
"Pandas DataFrame:"
)
print
(
df
)
def
test_matplotlib
():
print
(
"
\n
Testing Matplotlib..."
)
x
=
np
.
linspace
(
0
,
10
,
100
)
y
=
np
.
sin
(
x
)
plt
.
plot
(
x
,
y
)
plt
.
title
(
"Sine Wave"
)
plt
.
xlabel
(
"x"
)
plt
.
ylabel
(
"sin(x)"
)
plt
.
show
()
def
test_sklearn
():
print
(
"
\n
Testing Scikit-learn (Linear Regression)..."
)
X
=
np
.
array
([[
1
],
[
2
],
[
3
]])
# 特征变量
y
=
np
.
array
([
2
,
4
,
6
])
# 目标变量
model
=
LinearRegression
()
model
.
fit
(
X
,
y
)
prediction
=
model
.
predict
()
# 提供输入特征
print
(
"Prediction for x=4:"
,
prediction
[
0
])
def
test_torch
():
print
(
"
\n
Testing PyTorch..."
)
x
=
torch
.
tensor
([
1.0
,
2.0
,
3.0
])
y
=
x
*
2
print
(
"Torch tensor result:"
,
y
)
if
__name__
==
"__main__"
:
test_numpy
()
test_pandas
()
test_matplotlib
()
# test_sklearn()
test_torch
()
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment