我正在使用 Python 3.7 和 numpy 1.18。我有一个形状为 (28, 28, 3) 的多维 numpy 数组,在这个 np 数组中,我想删除 20% 的最小权重。删除 20% 的最小权重意味着我用 0 掩盖这些数字。
(28, 28, 3) 的 20% = 470.4 = 470(四舍五入后)。
那么,对于这个 np 数组,对于 470 个最小的数字,我如何将它们屏蔽为零?
谢谢!
我是 R 的初学者,正在处理如下一些数据-
月份 <- 1 2 3 4 5 6 7 8 9 10 11 12
销售额 <- 50 60 80 50 40 30 35 55 70 60 50 40
我必须使用plot()函数来绘制这些数据,我可以通过对其进行某些编辑来完成,如下所示-
plot(Month, Coffee, type='l', ylim=c(0, 100))
abline(h=max(Coffee), col='red')
Run Code Online (Sandbox Code Playgroud)
新的要求是将 X 轴上的“月份”名称绘制为实际月份名称,即一月、二月、三月……、十二月。
我尝试使用-
n_month <- format(ISOdate(2017,1:12,1),"%B")
plot(n_month, Coffee, type='l', ylim=c(0, 100))
plot(n_month, Coffee, type='l', ylim=c(0, 100), xlim=(1, 12))
Run Code Online (Sandbox Code Playgroud)
我还尝试了以下方法 -
# 'xaxt' to suppress labels on x-axis
plot(Month, Coffee, ylim=c(0,100), xlab="Month", ylab="Coffee", xaxt="n", type='l')
# 'axis' to add in my …Run Code Online (Sandbox Code Playgroud) 我正在阅读有关使用 TensorFlow 2.0 结合“GradientTape”API 创建神经网络的内容,并发现了以下代码:
model = tf.keras.Sequential((
tf.keras.layers.Reshape(target_shape=(28 * 28,), input_shape=(28, 28)),
tf.keras.layers.Dense(100, activation='relu'),
tf.keras.layers.Dense(100, activation='relu'),
tf.keras.layers.Dense(10)))
model.build()
optimizer = tf.keras.optimizers.Adam()
Run Code Online (Sandbox Code Playgroud)
在这段代码中,“model.build()”的用途/功能是什么?是编译设计好的神经网络吗?
其余的代码是:
compute_loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
compute_accuracy = tf.keras.metrics.SparseCategoricalAccuracy()
def train_one_step(model, optimizer, x, y):
with tf.GradientTape() as tape:
logits = model(x)
loss = compute_loss(y, logits)
grads = tape.gradient(loss, model.trainable_variables)
optimizer.apply_gradients(zip(grads, model.trainable_variables))
compute_accuracy(y, logits)
return loss
@tf.function
def train(model, optimizer):
train_ds = mnist_dataset()
step = 0
loss = 0.0
accuracy = 0.0
for x, y in train_ds:
step += 1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试用C语言编写一个程序,它有一个函数split_array.它需要一个指向动态分配的数组的指针,然后将其分成两半,即左右两部分.
该程序示例的代码是:
#include<stdio.h>
#include<stdlib.h>
void split_array(int *A, int x)
{
int *left=NULL, *right=NULL, i, mid=0;
mid=x/2;
left=(int*)malloc(sizeof(int)*mid);
if(left==NULL)
{
printf("\nError allocating memory. Aborting!\n\n");
exit(1);
}
if(x%2==0)
{
right=(int*)malloc(sizeof(int)*mid);
if(right==NULL)
{
printf("\nError allocating memory. Aborting!\n\n");
exit(1);
}
}
else
{
right=(int*)malloc(sizeof(int)*(mid+1));
if(right==NULL)
{
printf("\nError allocating memory. Aborting!\n\n");
exit(1);
}
}
for(i=0;i<mid;i++)
left[i]=A[i];
for(i=mid;i<x;i++)
right[i]=A[i];
printf("\nleft: ");
for(i=0;i<mid;i++)
printf("%d ", left[i]);
printf("\n");
printf("\nright: ");
for(i=mid;i<x;i++)
printf("%d ", right[i]);
printf("\n");
free(left);
free(right);
left=NULL;
right=NULL;
}
int main()
{
int *arr=NULL, i, …Run Code Online (Sandbox Code Playgroud) python-3.x ×2
c ×1
gcc ×1
linux ×1
numpy ×1
pgadmin-4 ×1
plot ×1
postgresql ×1
r ×1
tensorflow ×1
tf.keras ×1