这个问题已经在这里有了答案:
我有一个清单,我创建了一个清单以进行一些操作,同时仍保留原始清单。 但是,当我将org_list
设置为等于copy_list
时,它们变成同一件事,如果我更改copy_list
,org_list
也将更改。 例如:
org_list = ['y', 'c', 'gdp', 'cap']
copy_list = org_list
copy_list.append('hum')
print(copy_list)
print(org_list)
退货
['y', 'c', 'gdp', 'cap', 'hum']
['y', 'c', 'gdp', 'cap', 'hum']
我对实际发生的事情不太了解,但是看起来org_list
实际上正在将自身传递给copy_list
,因此它们实际上是同一件事。
有没有一种方法可以制作一个独立的org_list副本而无需做一些笨拙的事情:
copy_list = []
for i in org_list:
copy_list.append(i)
我之所以这样说,是因为我对其他类型的变量(例如熊猫数据框)也存在相同的问题。
我需要使用outputText
进行换行,以便可以利用属性rendered
。 我试过了
<h:outputText value="<br/>" escape="false" />
但是它产生了异常
The value of attribute "value" associated with an element type "null" must not contain the '<' character.
我需要使用自定义视图制作AlertDialog
。AlertDialog
的消息具有默认填充,但是当我设置一个视图时,它没有填充,因此我希望获得与消息相同的默认填充。 我使用的是扩展Holo主题的样式(如果相关)。
AlertDialog.Builder builder = new AlertDialog.Builder(PlaylistListView.this.getContext());
builder.setTitle("Title");
builder.setView(inflate(context, R.layout.music_player_create_dialog, null));
builder.setPositiveButton("OK", null);
builder.setNegativeButton("Cancel", null);
builder.show();
这是内容的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/abc_dialog_padding_material"
android:paddingRight="@dimen/abc_dialog_padding_material"
android:paddingTop="@dimen/abc_dialog_padding_top_material"
android:paddingBottom="@dimen/abc_dialog_padding_top_material">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title:"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:background="@null"
android:layout_marginTop="20dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/divider"/>
</LinearLayout>
如何将外部库中的资产包含到Angular CLI项目中
我正在下面尝试,但这不起作用,
"assets": [
"../node_modules/<external library>/assets/"
]
脚本工作正常,
"scripts": [
"../node_modules/<external library>/some.js",
"startup.js"
]
角版本:2.4.1
Angular CLI:1.0.0-beta.24
有什么建议吗?
我一直在Rails 2.3中使用Authlogic,但是现在我在使用Rails 3,我想我可以尝试一种新的身份验证解决方案。
Devise与Authlogic相比如何? 他们有什么区别?
因此,我正在我的第一个响应式网站上工作,该网站广泛使用了媒体查询。 我想知道是否应该优化一些常见的页面宽度。
我可能会有一个最大宽度(不能完全流畅),我想我可能会设置3-5个宽度,它们之间有一些有趣的CSS3过渡(类似于CSS Tricks的工作方式)。
目前我使用的数字有些随意:
@media all and (max-width: 599px){...}
@media all and (min-width: 600px) and (max-width:799px){...}
@media all and (min-width: 800px) and (max-width:1024px){...}
@media all and (min-width: 700px) and (max-width: 1024px){...}
@media all and (min-width: 1025px) and (max-width: 1399px){...}
@media all and (min-width: 1400px){...}
另外,我想我已经读到一些移动设备的表现与预期不符(@media
)。 这在哪里发挥作用,我应如何应对这些情况?
Keras的next(datagen)
模型方法期望生成器生成形状(输入,目标)的元组,其中两个元素均为NumPy数组。 该文档似乎暗示,如果我将next(datagen)
迭代器简单地包装在生成器中,并确保将Tensors转换为NumPy数组,那我应该很好。 这段代码给我一个错误:
import numpy as np
import os
import keras.backend as K
from keras.layers import Dense, Input
from keras.models import Model
import tensorflow as tf
from tensorflow.contrib.data import Dataset
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
with tf.Session() as sess:
def create_data_generator():
dat1 = np.arange(4).reshape(-1, 1)
ds1 = Dataset.from_tensor_slices(dat1).repeat()
dat2 = np.arange(5, 9).reshape(-1, 1)
ds2 = Dataset.from_tensor_slices(dat2).repeat()
ds = Dataset.zip((ds1, ds2)).batch(4)
iterator = ds.make_one_shot_iterator()
while True:
next_val = iterator.get_next()
yield sess.run(next_val)
datagen = create_data_generator()
input_vals = Input(shape=(1,))
output = Dense(1, activation='relu')(input_vals)
model = Model(inputs=input_vals, outputs=output)
model.compile('rmsprop', 'mean_squared_error')
model.fit_generator(datagen, steps_per_epoch=1, epochs=5,
verbose=2, max_queue_size=2)
这是我得到的错误:
Using TensorFlow backend.
Epoch 1/5
Exception in thread Thread-1:
Traceback (most recent call last):
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 270, in __init__
fetch, allow_tensor=True, allow_operation=True))
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2708, in as_graph_element
return self._as_graph_element_locked(obj, allow_tensor, allow_operation)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2787, in _as_graph_element_locked
raise ValueError("Tensor %s is not an element of this graph." % obj)
ValueError: Tensor Tensor("IteratorGetNext:0", shape=(?, 1), dtype=int64) is not an element of this graph.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jsaporta/anaconda3/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/jsaporta/anaconda3/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/keras/utils/data_utils.py", line 568, in data_generator_task
generator_output = next(self._generator)
File "./datagen_test.py", line 25, in create_data_generator
yield sess.run(next_val)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 895, in run
run_metadata_ptr)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1109, in _run
self._graph, fetches, feed_dict_tensor, feed_handles=feed_handles)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 413, in __init__
self._fetch_mapper = _FetchMapper.for_fetch(fetches)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 233, in for_fetch
return _ListFetchMapper(fetch)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 340, in __init__
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 340, in <listcomp>
self._mappers = [_FetchMapper.for_fetch(fetch) for fetch in fetches]
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 241, in for_fetch
return _ElementFetchMapper(fetches, contraction_fn)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 277, in __init__
'Tensor. (%s)' % (fetch, str(e)))
ValueError: Fetch argument <tf.Tensor 'IteratorGetNext:0' shape=(?, 1) dtype=int64> cannot be interpreted as a Tensor. (Tensor Tensor("IteratorGetNext:0", shape=(?, 1), dtype=int64) is not an element of this graph.)
Traceback (most recent call last):
File "./datagen_test.py", line 34, in <module>
verbose=2, max_queue_size=2)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 87, in wrapper
return func(*args, **kwargs)
File "/home/jsaporta/anaconda3/lib/python3.6/site-packages/keras/engine/training.py", line 2011, in fit_generator
generator_output = next(output_generator)
StopIteration
奇怪的是,在我初始化datagen
的位置之后直接添加包含next(datagen)
的行会导致代码正常运行,没有错误。
为什么我的原始代码不起作用? 当我将该行添加到代码中时,为什么它开始起作用? 是否有一种更有效的方式将TensorFlow的Dataset API与Keras结合使用,而又不涉及将Tensors转换为NumPy数组然后再次返回?
在我的项目中,我获得了json格式的API响应。 我得到UTC时间格式的时间的字符串值,例如Jul 16, 2013 12:08:59 AM
。
我需要将其更改为本地时间。那就是我们使用此应用程序需要显示当地时间的地方。 我该怎么做?
这是我尝试过的一些代码:
String aDate = getValue("dateTime", aEventJson);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss z");
simpleDateFormat.setTimeZone(TimeZone.getDefault());
String formattedDate = simpleDateFormat.format(aDate);
假设日期包含Jul 16, 2013 12:08:59 AM
我使用Hibernate创建了一个程序。
程序到达主要功能端,但是程序正在运行。
我不知道使用Hibernate 4.x版配置SessionFactory
时是否会发生这种情况。
配置方式错误吗?
manual1_1_first_hibernate_apps.java
public static void main(String[] args) {
args[0] ="list";
if (args.length <= 0) {
System.err.println("argement was not given");
return;
}
manual1_1_first_hibernate_apps mgr = new manual1_1_first_hibernate_apps();
if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event", new Date());
}
else if (args[0].equals("list")) {
mgr.<Event>listEvents().stream()
.map(e -> "Event: " + e.getTitle() + " Time: " + e.getDate())
.forEach(System.out::println);
}
Util.getSessionFactory().close();
}
private <T> List<T> listEvents() {
Session session = Util.getSessionFactory().getCurrentSession();
session.beginTransaction();
List<T> events = Util.autoCast(session.createQuery("from Event").list());
session.getTransaction().commit();
return events;
}
Util.java
private static final SessionFactory sessionFactory;
/**
* build a SessionFactory
*/
static {
try {
// Create the SessionFactory from hibernate.cfg.xml
// hibernate version lower than 4.x are as follows
// # it successful termination. but buildSessionFactory method is deprecated.
// sessionFactory = new Configuration().configure().buildSessionFactory();
// version 4.3 and later
// # it does not terminate. I manually terminated.
Configuration configuration = new Configuration().configure();
StandardServiceRegistry serviceRegistry =
new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
catch (Throwable ex) {
// Make sure you log the exception, as it might be swallowed
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
/**
* @return built SessionFactory
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
程序终止并使用buildSessionFactory方法时,以下控制台日志片段。
2 08, 2014 8:42:25 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:derby:D:\Java\jdk1.7.0_03(x86)\db\bin\testdb]
但是,如果不使用已弃用的buildSessionFactory方法并终止(程序正在运行),则不会出现上述两行。
环境:
Hibernate 4.3.1 DERBY JRE 1.8 IntelliJ IDEA 13
似乎Radix sort具有非常好的平均用例性能,即O(kN):[http://en.wikipedia.org/wiki/Radix_sort]
但是似乎大多数人仍在使用快速排序,不是吗?
此错误消息是什么意思,我该如何解决? 这是从Windows 7上的Google Chrome v33.0控制台获得的。
无法加载资源:net :: ERR_CONTENT_LENGTH_MISMATCH [http://and.img.url/here.png]
我正在尝试使用jQuery更改图像的src
属性。 例如这样(简化):
$('.image-prld').attr('src', someDynamicValue);
页面上大约有30张图像。 每当我重新加载页面时,随机图像都会发生上述错误。 但是有时它对于所有图像都运行良好,没有任何错误。
发生此错误时,特定的图像显示如下:
但是,当我在新选项卡上打开错误消息旁边的链接时,图像正在加载,这从逻辑上说图像是有效的并且存在。
我可以使用以下方式按名称对Kubernetes Pod进行排序:
kubectl get pods --sort-by=.metadata.name
如何使用年龄kubectl
对它们(或其他资源)进行排序?
根据Java文档,response
方法method_()
无法返回值。 但是,我确实想知道是否有任何解决方法。
其实我有一个方法,它调用:
public class Endpoint{
public method_(){
RunnableClass runcls = new RunnableClass();
runcls.run()
}
}
其中方法response
为:
public class RunnableClass implements Runnable{
public jaxbResponse response;
public void run() {
int id;
id =inputProxy.input(chain);
response = outputProxy.input();
}
}
我想访问method_()
中的response
变量,这可能吗?
我正在尝试做一个jQuery GET,我想发送一个参数。
这是我的功能:
$(function() {
var availableProductNames;
$.get("manageproducts.do?option=1", function(data){
availableProductNames = data.split(",");;
alert(availableProductNames);
$("#nameInput").autocomplete({
source: availableProductNames
});
});
});
这似乎行不通; 当我使用request.getParameter("option")
时,我的servlet中为空;
如果我在浏览器[http://www.myite.com/manageproducts.do?option=1]中输入链接,则可以正常运行。
我也尝试过:
$.get(
"manageproducts.do?",
{option: "1"},
function(data){}
这也不起作用。
你能帮我么?
编辑:
也尝试过
$.ajax({
type: "GET",
url: "manageproducts.do",
data: "option=1",
success: function(msg){
availableProductNames = msg.split(",");
alert(availableProductNames);
$("#nameInput").autocomplete({
source: availableProductNames
});
}
});
仍然得到相同的结果。
通过多活动应用程序流束缚Google+ api客户端生命周期的一种好/推荐方法是什么? 使活动依赖于onConnected api客户端方法来触发其功能,将其用作一次性的“激活”事物,或者完全用作其他事物?
我目前正在努力了解如何在我的Android应用中正确使用Google+登录,该应用有多个活动。
这个想法是,在第一个阶段中,使用G +登录仅用于验证用户身份并能够获取她的电子邮件,发送通知和类似内容。 最终,我计划推出其他Google功能,例如Maps或其他Google Play服务,因此我认为已经非常有用。
但是,我的应用程序运行不正常,因此我将问题缩小到以下事实:当存在多个活动时,我还不了解应用程序周期中的G +登录。
实现此auth方法的正确或推荐方法是什么? 也许有某种模式可以指导我朝正确的方向发展吗?
例如,我发现了一个非常简单的api客户端生命周期图,但这与应用程序流程有何关系?
最初,我有一个登录活动,在其中输入了登录按钮。 按照Google的指南,我可以登录,并在调用onConnected方法时,启动“家庭活动”(有点像仪表板或应用程序的主屏幕)。
这有点奏效。 例如,为每个活动处理onStart和onStop的好方法是什么? 我应该为每个活动每次都重新连接和重新认证api客户端吗? 因此,拥有BaseActivity来实现所有这些可能是一个好主意。
另一个问题是,我应该使用相同的api客户端对象并以某种方式传递它,还是将其存储在Base Activity类中? 还是应该每次都创建和初始化一个新的api客户端对象?
仅使用登录活动对G +进行身份验证,然后获取电子邮件并将其存储在本地数据库中,然后将用户标记为“已认证”或“活动”或类似内容,该怎么办? 这样可以避免我每次关闭应用程序或暂停连接时都必须重新进行身份验证,甚至节省了一些电池电量。
该应用并未真正使用Google+发布或类似的其他功能。 理想情况下,它应该可以在脱机状态下正常运行,并且只需要连接即可进行初始身份验证之类的东西或其他一次性的东西。
我们非常感谢您在正确方向上提出的任何建议或指示。
编辑:我已经阅读了所有可以找到的使用Google+的指南和教程,并且每个人都从一个活动角度解决了这个问题。 我认为这是一个足够普遍的问题,它将从某种模式或至少是一条通用准则中受益。
我想在项目中使用自定义组件,并且要将其添加到如下所示的枚举属性中,我该怎么做?
<com.abb.abbcustomcompanents.buttons.AbbButton
android:id="@+id/abbBtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:Type="How can i use enum here"
/>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="abbButton">
<attr name="Type" format="enum"/>
<attr name="onAction" format="string"/>
</declare-styleable>
</resources>
谢谢 !
我在GHCI中执行以下操作:
:m + Data.Map
let map = fromList [(1, 2)]
lookup 1 map
GHCI知道地图是(Map Integer Integer)。 那么,为什么在类型清晰且可以避免的情况下在Prelude.lookup和Data.Map.lookup之间声明歧义?
<interactive>:1:0:
Ambiguous occurrence `lookup'
It could refer to either `Prelude.lookup', imported from Prelude
or `Data.Map.lookup', imported from Data.Map
> :t map
map :: Map Integer Integer
> :t Prelude.lookup
Prelude.lookup :: (Eq a) => a -> [(a, b)] -> Maybe b
> :t Data.Map.lookup
Data.Map.lookup :: (Ord k) => k -> Map k a -> Maybe a
我在名为bot4CA.py的模块上使用cProfile,因此在控制台中键入:
python -m cProfile -o thing.txt bot4CA.py
模块运行并退出后,它将创建一个名为Thing.txt的文件,当我打开它时,那里有一些信息,其余的是一堆字符,而不是我想要的整洁的数据文件。 是否有人知道如何使用cProfile并最终得到整齐有序的数据表,就像在命令行中正常使用它一样(除了在文件中)?这是.txt文件中某些数据的示例:
{( s) build\bdist.win32\egg\colorama\winterm.pyi' t reset_all( i i gpàÂs% ?geOÙHÌœE?{( s- build\bdist.win32\egg\colorama\ansitowin32.pyi¥
我真正想要的是,当您调用cProfile.run()时会发生什么,结果将导致打印出整齐有序的表,该表显示了所有功能的执行时间(而不是打印出来),而不是打印出来,并保存在文件中,因为此程序相当大并且运行很多 功能。
我已经看到许多Clojure程序员对新的core.async库充满热情,尽管看起来很有趣,但是我很难看清它如何符合Clojure原理,所以我有以下问题:
由于“ go”是一个宏(因此修改了代码结构),并确保“ <!” 直接在go块中使用,无法使用“ <!” 在另一个函数中,如下所示:
(defn take-and-print [c]
(println (<! c)))
(def ch (chan 1))
(>!! ch 123)
(go (take-and-print ch))
Assert failed: <! used not in (go ...) block
在我看来,这阻止了简单性和可组合性。 为什么没有问题?
可能是由于前两个问题造成的,很多带有core.async的代码都使用了诸如循环/递归等较低级别的结构,而不是map / filter / reduce。 这不是倒退一步吗?
我在哪里错过了重点?
提前致谢。