我有一个numpy数组:
array([ 6., 13., 10., 9., 5., 4., 4., 4., 3., 5., 4., 20., 6.,
14., 8., 6., 3., 3., 3., 2., 2., 5., 6., 11., 11., 11.,
9., 3., 3., 3., 2., 3., 2., 3., 6., 11., 15., 12., 5.,
3., 3., 5., 2., 2., 2., 2., 3., 4., 7., 2., 8., 2.,
3., 2., 1., 3., 1., 1., 5., 5., 4., 2., 5., 2., 3.,
2., 2., 2., 1., 2., 4., 11., 5., 4., 3., 4., 3., 3.,
3., 4., 3., 4., 2., 6., 6., 3., 3., 2., 3., 4., 2.,
3., 2., 4., 2., 5., 4., 3., 2., 2., 3., 2., 2., 2.,
2., 3., 3.], dtype=float32)
...但是我想使其包含整数而不是浮点数。你能帮我解决这个问题吗?
答案 0 :(得分:1)
您可以使用Numpy的内置方法astype
:
a = np.ones((3,3))
print(a.dtype) #defaults to float64
a = a.astype(int) #changes to int
答案 1 :(得分:1)
<Style TargetType="Menu" x:Key="m_menu_Menu">
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="FontFamily" Value="Roboto"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Style TargetType="TextBlock" x:Key="m_top_menu_TextBlock_Farm">
<Setter Property="FontSize" Value="18"></Setter>
<Setter Property="FontFamily" Value="Roboto"></Setter>
<Setter Property="FontWeight" Value="Bold"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="Margin" Value="0 0 10 0"></Setter>
</Style>
<Style TargetType="materialDesign:PackIcon" x:Key="m_top_menu_materialDesign_Farm">
<Setter Property="Width" Value="30"></Setter>
<Setter Property="Height" Value="30"></Setter>
<Setter Property="VerticalAlignment" Value="Center"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
<Setter Property="Foreground" Value="White"></Setter>
</Style>
<Menu Background="{x:Null}" Style="{StaticResource m_menu_Menu}" VerticalAlignment="Stretch">
<MenuItem x:Name="m_addWork" Height="75">
<MenuItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="PlusCircle" Style="{StaticResource m_top_menu_materialDesign_Farm}" Height="43" Width="45"/>
<TextBlock Text="Add" Style="{StaticResource m_top_menu_TextBlock_Farm}"/>
<materialDesign:PackIcon Kind="ChevronDown" Style="{StaticResource m_top_menu_materialDesign_Farm}"/>
</StackPanel>
</MenuItem.Header>
</MenuItem>
</Menu>