我正在使用Apache POI生成Excel文件.我需要删除工作表中的所有边框.如何使用Apache PIO 3.11和Microsoft Excel 2007实现此目的?
这是我到目前为止的代码:
package models;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import java.io.FileOutputStream;
import java.util.List;
public class Excel {
public static void writeDocument() {
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet("sheet");
//first font
Font font1 = workbook.createFont();
font1.setBoldweight(Font.BOLDWEIGHT_BOLD);
//first style
CellStyle style1 = workbook.createCellStyle();
style1.setBorderLeft(CellStyle.BORDER_NONE);
style1.setBorderRight(CellStyle.BORDER_NONE);
style1.setBorderBottom(CellStyle.BORDER_NONE);
style1.setBorderTop(CellStyle.BORDER_NONE);
//second style
CellStyle style2 = workbook.createCellStyle();
style2.setFont(font1);
style2.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style2.setAlignment(CellStyle.ALIGN_CENTER);
style2.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style2.setFillPattern(CellStyle.SOLID_FOREGROUND);
style2.setBorderBottom(CellStyle.BORDER_THIN);
style2.setBottomBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
style2.setBorderLeft(CellStyle.BORDER_THIN);
style2.setLeftBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
style2.setBorderRight(CellStyle.BORDER_THIN);
style2.setRightBorderColor(IndexedColors.GREY_25_PERCENT.getIndex());
style2.setBorderTop(IndexedColors.GREY_25_PERCENT.getIndex());
for(int i=0; i< 100 ; i++){ …Run Code Online (Sandbox Code Playgroud) import tensorflow as tf
array = tf.Variable(tf.random_normal([10]))
i = tf.constant(0)
l = []
def cond(i,l):
return i < 10
def body(i,l):
temp = tf.gather(array,i)
l.append(temp)
return i+1,l
index,list_vals = tf.while_loop(cond, body, [i,l])
Run Code Online (Sandbox Code Playgroud)
我想以与上面代码中描述的类似方式处理张量数组.在while循环的主体中,我想逐个元素地处理数组以应用一些函数.为了演示,我给了一个小代码片段.但是,它给出了如下错误消息.
ValueError: Number of inputs and outputs of body must match loop_vars: 1, 2
Run Code Online (Sandbox Code Playgroud)
任何帮助解决这个问题表示赞赏.
谢谢
Keras的TensorFlow后端是否依赖于热切的执行?
如果不是这种情况,我可以基于Keras和TensorFlow操作构建TensorFlow图,然后使用Keras高级API训练整个模型吗?
我想在Tensorflow中导入keras.engine.topology。如果我想使用Keras的Tensorflow版本,我曾经在每个Keras导入的开头添加tensorflow一词。
例如:而不是写:
from keras.layers import Dense, Dropout, Input
Run Code Online (Sandbox Code Playgroud)
我只是编写以下代码,它可以正常工作:
from tensorflow.keras.layers import Dense, Dropout, Input
Run Code Online (Sandbox Code Playgroud)
但这不是这种特定导入的情况:
from tensorflow.keras.engine.topology import Layer, InputSpec
Run Code Online (Sandbox Code Playgroud)
我收到以下错误消息:
No module named 'tensorflow.keras.engine'
Run Code Online (Sandbox Code Playgroud) 我想在没有任何输入的情况下实现Keras自定义层,只是可训练的权重。
这是到目前为止的代码:
class Simple(Layer):
def __init__(self, output_dim, **kwargs):
self.output_dim = output_dim
super(Simple, self).__init__(**kwargs)
def build(self):
self.kernel = self.add_weight(name='kernel', shape=self.output_dim, initializer='uniform', trainable=True)
super(Simple, self).build()
def call(self):
return self.kernel
def compute_output_shape(self):
return self.output_dim
X = Simple((1, 784))()
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
__call__() missing 1 required positional argument: 'inputs'
在Keras中没有输入的情况下,有没有构建自定义层的解决方法?
在Keras中,对于密集层,我们可以使用参数activity_regularizer。在Tensorflow中,没有类似的参数。
凯拉斯:
from keras import regularizers
encoding_dim = 32
input_img = Input(shape=(784,))
# add a Dense layer with a L1 activity regularizer
encoded = Dense(encoding_dim, activation='relu', activity_regularizer=regularizers.l1(10e-5))(input_img)
decoded = Dense(784, activation='sigmoid')(encoded)
autoencoder = Model(input_img, decoded)
Run Code Online (Sandbox Code Playgroud)
如何在tensorflow中制作一个activity_regularizer?
我有两个 Keras 模型(功能 API)共享一些层。我想知道我是否训练第一个模型,第二个模型是否会自动更新其共享层的权重,还是应该手动加载权重。
我从文档中知道层可以在同一个模型中共享,但我对这种特殊情况没有任何线索。
我还想知道具有共享层的 Keras 模型是共享相同的计算图还是它们具有独立的计算图。
我将 2 个 Numpy 数组保存为字典。
当我从二进制文件加载数据时,我得到另一个ndarray. 我可以将加载的 Numpy 数组用作字典吗?
这是我的代码和脚本的输出:
import numpy as np
x = np.arange(10)
y = np.array([100, 101, 102, 103, 104, 105, 106, 107])
z = {'X': x, 'Y': y}
np.save('./data.npy', z)
z1 = np.load('./data.npy')
print(type(z1))
print(z1)
print(z1['X']) #this line will generate an error
Run Code Online (Sandbox Code Playgroud)
输出:{'X': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), 'Y': array([100, 101, 102, 103, 104, 105 , 106, 107])}
python ×6
tensorflow ×6
keras ×5
apache-poi ×1
arrays ×1
dictionary ×1
java ×1
numpy ×1
python-2.7 ×1
while-loop ×1