答:
I had this very same problem using a different set of functions to find closest point on the curve.

The progressive search

```<code>function localMinimum(minX, maxX, ƒ, ε) {
    if (ε===undefined) ε=1e-15;
    let m=minX, n=maxX, k;
    while ((n-m)>ε) {
        k = (n+m)/2;
        if (ƒ(m)<ƒ(n)) n=k;
        else           m=k;
    }
    return k;
}
</code>```

is at fault as it will close in on the wrong local. From memory it is the derivative (or second derivative) of the curve that is the distance from the point that will show an inflection point where you are getting the wrong result. In other words at that part of the curve it moves closer and closer to your point and then starts to move away. The search function assume that this inflection point is the point you are looking for.

The solution is systematic search (at some resolution) then a progressive search for the final result.

Title: Local minimum function getting stuck not at minimum

Body:
Summary

My simple function performing a binary search for a local minimum often returns spurious values corresponding to exactly ¼, ½, and ¾ of the search. Why is this happening?

/**
 * minX  : the smallest input value
 * maxX  : the largest input value
 * ƒ     : a function that returns a value `y` given an `x`
 * ε     : how close in `x` the bounds must be before returning
 * return: the `x` value that produces the smallest `y`
 */
function localMinimum(minX, maxX, ƒ, ε) {
    if (ε===undefined) ε=1e-15;
    let m=minX, n=maxX, k;
    while ((n-m)>ε) {
        k = (n+m)/2;
        if (ƒ(m)<ƒ(n)) n=k;
        else           m=k;
    }
    return k;
}

Live Demo: http://phrogz.net/svg/closest-point-on-bezier_broken.html

The demo lets you adjust a cubic Bézier curve, move the mouse around, and attempts to find a point on the curve closest to the mouse location. In the screenshots below, you can see the curve (black), the location of the mouse (centered in the gray circle), the location found on the curve (red dot), a brute-force graph of the distance from the cursor to each point on the curve (lower right corner), and the t parameter that was calculated as the local minimum (red text).

These screenshots represent the worst case. In them the mouse location is very close to the line, and the "local minimum" function is returning a point that is NOT the local minimum. If you experiment with the demo, you will see that in many cases the local minimum function is working as intended. Just…not near some of the early binary search bounds.

Guide to the Code

The localMinimum() function (line 225) is called by the closestPoint() function (line 194):

/**
 * out   : A vmath vector to modify with the point value
 * curve : Array of vectors as control points for a Bézier curve (any degree)
 * pt    : Object with .x/.y to find the point closest to
 * return: A parameter t representing the location of `out`
 */
function closestPoint(out, curve, pt, tmps) {
    let vec=vmath[ 'w' in curve[0] ? 'vec4' : 'z' in curve[0] ? 'vec3' : 'vec2' ];
    return localMinimum(0, 1,
      t => vec.squaredDistance(pt, bézierPoint(out, curve, t)));
}

The bézierPoint() function (line 207) uses De Casteljau's algorithm to calculate a point along the curve parameterized by t. This function works as expected, tested independently of the rest of the problem.

The squaredDistance() function is part of the vmath library, and is as simple as you would imagine.

What am I missing? How is my local minima function failing?

Body:
I had this very same problem using a different set of functions to find closest point on the curve.

The progressive search

function localMinimum(minX, maxX, ƒ, ε) {
    if (ε===undefined) ε=1e-15;
    let m=minX, n=maxX, k;
    while ((n-m)>ε) {
        k = (n+m)/2;
        if (ƒ(m)<ƒ(n)) n=k;
        else           m=k;
    }
    return k;
}

is at fault as it will close in on the wrong local. From memory it is the derivative (or second derivative) of the curve that is the distance from the point that will show an inflection point where you are getting the wrong result. In other words at that part of the curve it moves closer and closer to your point and then starts to move away. The search function assume that this inflection point is the point you are looking for.

The solution is systematic search (at some resolution) then a progressive search for the final result.


来源: stackexchange

问:
Structuring a medium/small sized javascript program
So as a pet project I'm planning on making a simple game using AJAX, Javascript and the Canvas element. While I do have javascript experience it is mostly in very small snippets for sites. I come from a Java background and don't want to start doing this in a "Java" way. Is there any resources that will help me structure and layout my code in a way befitting javascript?</p>

答:
Look at this question:

How to structure my javascript/jquery code?

ContentLicense: CC BY-SA 2.5


问:
Issues with saving xml document to xml file in the output directory. c# Xamarin
I'm making an application that loads and saves profile nodes to an external xml document in my output directory. It worked fine when I was opening it from my Assets folder but since that is read only (I think) I need to have it read and write from the output directory or another folder.
Like this:

```<code>XmlDocument users = new XmlDocument();
users.Load("users.xml");
</code>```

However I get this error when this code runs:

"System.IO.FileNotFoundException: Could not find file "/users.xml"."

I've ticked the secondary storage permissions but i'm still a bit confused about just referencing a file in the output directory.

Would also appreciate the help for saving too as I assume the same error will occur:

```<code>users.DocumentElement.AppendChild(user);
users.Save("users.xml");
</code>```

Thank you in advance.

答:
In xamarin form you can try this code to load xml file from PCL project.</p>

```<code>var assembly = typeof(TestClass).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream(“PrjectName.FileName”);
using (var reader = new System.IO.StreamReader(stream))
{
    var serializer = new XmlSerializer(typeof(List<BuildOptions>)); var listData = (List<T>)serializer.Deserialize(reader);
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm making an application that loads and saves profile nodes to an external xml document in my output directory. It worked fine when I was opening it from my Assets folder but since that is read only (I think) I need to have it read and write from the output directory or another folder.
Like this:

XmlDocument users = new XmlDocument();
users.Load("users.xml");

However I get this error when this code runs:

"System.IO.FileNotFoundException: Could not find file "/users.xml"."

I've ticked the secondary storage permissions but i'm still a bit confused about just referencing a file in the output directory.

Would also appreciate the help for saving too as I assume the same error will occur:

users.DocumentElement.AppendChild(user);
users.Save("users.xml");

Thank you in advance.

Body:
In xamarin form you can try this code to load xml file from PCL project.

var assembly = typeof(TestClass).GetTypeInfo().Assembly;
Stream stream = assembly.GetManifestResourceStream(“PrjectName.FileName”);
using (var reader = new System.IO.StreamReader(stream))
{
    var serializer = new XmlSerializer(typeof(List<BuildOptions>)); var listData = (List<T>)serializer.Deserialize(reader);
}


问:
how can i find the sum of all integers given in the string by using JavaScript?
How do I calculate the sum of all the numbers in a string by using the JavaScript ? In the example below, the expected result would be 2+0+1+5. My attempt is below. </p>

```<code>var a = "weare20boysand15girls";
    var i;
    for(i=0; i<a.length; i++){
        var b = Number(a[i]);
        var c=0;
        c += b;
        console.log(c);
</code>```

答:
You could</p>

```<code>const input = "weare20boysand15girls";
const result =
    // Transform the string to an array.
    input.split("")
    // Use the reduce function to sum only the elements that are numbers.
    .reduce((sum, el) => isNaN(el) ? sum : sum + Number(el), 0);
</code>```

Body:
How do I calculate the sum of all the numbers in a string by using the JavaScript ? In the example below, the expected result would be 2+0+1+5. My attempt is below.

var a = "weare20boysand15girls";
    var i;
    for(i=0; i<a.length; i++){
        var b = Number(a[i]);
        var c=0;
        c += b;
        console.log(c);

Body:
You could

const input = "weare20boysand15girls";
const result =
    // Transform the string to an array.
    input.split("")
    // Use the reduce function to sum only the elements that are numbers.
    .reduce((sum, el) => isNaN(el) ? sum : sum + Number(el), 0);


问:
Ecto changeset - skip nil fields
How do I add a field to a changeset only if the field is not nil? I don't want to update the value in the database if the value is nil. I need to check 3 fields and only update the ones that are not nil.

current code:

```<code>  put "/products" do
    errors = {}
    IO.inspect(conn.body_params)

    product = Api.Product |> Api.Repo.get(conn.query_params["id"])
    IO.inspect(product)

    if conn.body_params["image"] do
      changeset = Api.Product.changeset(product, %{image: conn.body_params["image"]})
    end

    if conn.body_params["description"] do
      changeset = Api.Product.changeset(product, %{description: conn.body_params["description"]})
    end

    if conn.body_params["price"] do
      changeset = Api.Product.changeset(product, %{price: conn.body_params["price"]})
    end
    case Api.Repo.update(changeset) do
      {:ok, product} ->
        errors = Tuple.append(errors, "Product updated")
      {:error, changeset} ->
        errors = Tuple.append(errors, "Product not updated")
    end

    conn
      |> put_resp_content_type("application/json")
      |> send_resp(200, Poison.encode!(%{
          successs: "success",
          errors: Tuple.to_list(errors)
      }))
  end
</code>```

答:
You can create a new params map with only the keys which the schema accepts and whose value is not nil using for, and pass that to changeset/2:

```<code>product = Api.Product |> Api.Repo.get(conn.query_params["id"])
params = for key <- ~w(image description price), value = conn.body_params[key], into: %{}, do: {key, value}
changeset = Api.Product.changeset(product, params)
case Api.Repo.update(changeset) do
  ...
end
</code>```

Title: Ecto changeset - skip nil fields

Body:
How do I add a field to a changeset only if the field is not nil? I don't want to update the value in the database if the value is nil. I need to check 3 fields and only update the ones that are not nil.

current code:

  put "/products" do
    errors = {}
    IO.inspect(conn.body_params)

    product = Api.Product |> Api.Repo.get(conn.query_params["id"])
    IO.inspect(product)

    if conn.body_params["image"] do
      changeset = Api.Product.changeset(product, %{image: conn.body_params["image"]})
    end

    if conn.body_params["description"] do
      changeset = Api.Product.changeset(product, %{description: conn.body_params["description"]})
    end

    if conn.body_params["price"] do
      changeset = Api.Product.changeset(product, %{price: conn.body_params["price"]})
    end
    case Api.Repo.update(changeset) do
      {:ok, product} ->
        errors = Tuple.append(errors, "Product updated")
      {:error, changeset} ->
        errors = Tuple.append(errors, "Product not updated")
    end

    conn
      |> put_resp_content_type("application/json")
      |> send_resp(200, Poison.encode!(%{
          successs: "success",
          errors: Tuple.to_list(errors)
      }))
  end

Body:
You can create a new params map with only the keys which the schema accepts and whose value is not nil using for, and pass that to changeset/2:

product = Api.Product |> Api.Repo.get(conn.query_params["id"])
params = for key <- ~w(image description price), value = conn.body_params[key], into: %{}, do: {key, value}
changeset = Api.Product.changeset(product, params)
case Api.Repo.update(changeset) do
  ...
end


问:
how to make hamburger menu fully visible
by default half of hamburger is shown, as seen at the top left corner of the screenshot. I want to display full hamburger. code is taken from https://developer.android.com/training/implementing-navigation/nav-drawer.html. how can I do this?

答:
Seems you are using very old technique to create Navigation Drawer. Its around 4 years old code and seems perfect regarding old version.

FYI, previously this kind of UI was done using DrawerLayout with ListView. But now android itself officially introduced sliding panel menu by introducing a newer concept called Navigation Drawer in which we combine DrawerLayout and NavigationView to achieve the desired output.

How to make hamburger menu fully visible?

SOLUTION:

Use AppCompatActivity instead of Activity and use AppCompat theme to achieve your desired output.

Use NavigationView instead of ListView.

Here is an example of NavigationView:

```<code><android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true">

     <!-- Your contents -->

     <android.support.design.widget.NavigationView
         android:id="@+id/navigation"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:layout_gravity="start"
         app:menu="@menu/my_navigation_items" />
 </android.support.v4.widget.DrawerLayout>
</code>```

Here is a very good tutorial: Android Sliding Menu using Navigation Drawer

Hope this will help~

Body:
Seems you are using very old technique to create Navigation Drawer. Its around 4 years old code and seems perfect regarding old version.

FYI, previously this kind of UI was done using DrawerLayout with ListView. But now android itself officially introduced sliding panel menu by introducing a newer concept called Navigation Drawer in which we combine DrawerLayout and NavigationView to achieve the desired output.

How to make hamburger menu fully visible?

SOLUTION:

Use AppCompatActivity instead of Activity and use AppCompat theme to achieve your desired output.

Use NavigationView instead of ListView.

Here is an example of NavigationView:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:fitsSystemWindows="true">

     <!-- Your contents -->

     <android.support.design.widget.NavigationView
         android:id="@+id/navigation"
         android:layout_width="wrap_content"
         android:layout_height="match_parent"
         android:layout_gravity="start"
         app:menu="@menu/my_navigation_items" />
 </android.support.v4.widget.DrawerLayout>

Here is a very good tutorial: Android Sliding Menu using Navigation Drawer

Hope this will help~


问:
How can I preserve line breaks from EditText?
The following ignore new lines when I display them

```<code>private void post() {
        String subject = "";
        String message = "";
        subject = etSubject.getText().toString();
        message = etMessage.getText().toString();
</code>```

edit: My edittext is already set to multiline however when I write multilined text in it it's returned as a single line with the cover above

edit2: i am getting the text from an editText and displaying it on a textview

答:
Try this, it should works</p>

```<code>message = etMessage.getText().toString().replaceAll("[\r\n]+", "\n");
</code>```

Body:
The following ignore new lines when I display them

private void post() {
        String subject = "";
        String message = "";
        subject = etSubject.getText().toString();
        message = etMessage.getText().toString();

edit: My edittext is already set to multiline however when I write multilined text in it it's returned as a single line with the cover above

edit2: i am getting the text from an editText and displaying it on a textview

Body:
Try this, it should works

message = etMessage.getText().toString().replaceAll("[\r\n]+", "\n");


问:
Virtualhost For Wildcard and Static Subdomain
This is what I basically have now:

```<code><VirtualHost *:80>
   DocumentRoot /var/www/app1
   ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
   DocumentRoot /var/www/example
   ServerName example.com
   ServerAlias *.example.com
</VirtualHost>
</code>```

This configuration makes app1.example.com a default serving VirtualHost.

Thus, when another.domain.com is pointed to *.example.com, it is served by app1.example.com.

How this configuration can be changed, so that another.domain.com would be served by *.example.com, still having app1.example.com, *.example.com and example.com working too?

Thank you.

P.S. I'm basing somewhat my question on this SO answer

答:
My own research gave me the only workaround so far. I've ended up using another port for app1.example.com. </p>

```<code><VirtualHost *:8080>
   DocumentRoot /var/www/app1
   ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
   DocumentRoot /var/www/example
   ServerName example.com
   ServerAlias *.example.com
</VirtualHost>
</code>```

Body:
This is what I basically have now:

<VirtualHost *:80>
   DocumentRoot /var/www/app1
   ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
   DocumentRoot /var/www/example
   ServerName example.com
   ServerAlias *.example.com
</VirtualHost>

This configuration makes app1.example.com a default serving VirtualHost.

Thus, when another.domain.com is pointed to *.example.com, it is served by app1.example.com.

How this configuration can be changed, so that another.domain.com would be served by *.example.com, still having app1.example.com, *.example.com and example.com working too?

Thank you.

P.S. I'm basing somewhat my question on this SO answer

Body:
My own research gave me the only workaround so far. I've ended up using another port for app1.example.com.

<VirtualHost *:8080>
   DocumentRoot /var/www/app1
   ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
   DocumentRoot /var/www/example
   ServerName example.com
   ServerAlias *.example.com
</VirtualHost>


问:
Why evaluate test data in a loop in tensorflow?
A few models implemented in TensorFlow posted on Github have their 'evaluation' function run a while loop, such as resnet (in resnet_main.py), etc.

I wonder why we need to evaluate the test data more than once.

答:
The test data is evaluated once: the loop is on its samples. The reason is rather mundane: when the test data is large, it cannot be processed as a whole because the whole network could not fit in memory. In that case, it is split in minibatches.

So even though training and testing loop on minibatches, the underlying reasons are indeed quite different.

EDIT

The outer loop has a different role: a new model is loaded at each iteration. This is used in case you run the evaluation in a different process that regularly reads the output of training on disk and evaluate them.

The rationale is explained here: it is useful when you are working in an environment where you can have training and testing occurring on different GPUs.


问:
Sorting model instances with Globalize3
The problem seems trivial, but I can't find any reasonable solution. I have list of countries with translations stored in Globalize3 translation tables. How can I fetch the list of countries sorted by name?

Country name isn't stored directly in the model, but in separate table. Is there any reasonable way to sort the result other than manual sql query, or manualy sorting result table after AR query is complete?

答:
Country.with_translations(I18n.locale).order('name') for current locale.

Edit:

You can also use fallbacks:

Country.with_translations(I18n.fallbacks[I18n.locale]).order('name')

Title: Sorting model instances with Globalize3


问:
SpriteKit animation issue Swift
I am having trouble with my animation in swift. The animation is not playing.

These are my swift files:

This is my sprite file:

```<code>import Foundation
import SpriteKit

class Dog: SKSpriteNode {

var dog = SKSpriteNode()

var textureAtlas = SKTextureAtlas()
var textureArray = [SKTexture]()

init() {
    super.init(texture: SKTexture(imageNamed:"dog_1"), color: UIColor.clear, size: CGSize(width: 44, height: 25))
    textureAtlas = SKTextureAtlas(named: "dog")

    for i in 1...textureAtlas.textureNames.count {

        let name = "dog_\(i).png"
        textureArray.append(SKTexture(imageNamed: name))

    }

}

func animate() {
    dog.run(SKAction.repeatForever(SKAction.animate(with: textureArray, timePerFrame: 0.1)))
}

func stopAnimation() {
    dog.removeAllActions()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
}
</code>```

This is my GameScene file:

```<code>import SpriteKit
import GameplayKit

class GameScene: SKScene {

var dog: Dog!

override func didMove(to view: SKView) {
    scene?.backgroundColor = UIColor(red: 132.0/255.0, green: 179.0/255.0, blue: 255.0/255.0, alpha: 1.0)

    addDog()

}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    dog.animate()
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    dog.stopAnimation()
}

func addDog() {

    dog = Dog()
    dog.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
    addChild(dog)
}

}
</code>```

I think the problem is in the animate function in the sprite file.

I have tried everything I can think of. Any help would be greatly appreciated.

答:
Within your class Dog you have a var dog that is initialised as an SKSpriteNode. Your start and stop animate functions then operate on that dog, not the class itself and not the other dog in your game scene. As that dog is never added to the scene your animation is never visible.

Remove the dog var and references to it from Dog - the animations should be running on your subclass Dog directly.

Title: SpriteKit animation issue Swift

Body:
I am having trouble with my animation in swift. The animation is not playing.

These are my swift files:

This is my sprite file:

import Foundation
import SpriteKit

class Dog: SKSpriteNode {

var dog = SKSpriteNode()

var textureAtlas = SKTextureAtlas()
var textureArray = [SKTexture]()

init() {
    super.init(texture: SKTexture(imageNamed:"dog_1"), color: UIColor.clear, size: CGSize(width: 44, height: 25))
    textureAtlas = SKTextureAtlas(named: "dog")

    for i in 1...textureAtlas.textureNames.count {

        let name = "dog_\(i).png"
        textureArray.append(SKTexture(imageNamed: name))

    }

}

func animate() {
    dog.run(SKAction.repeatForever(SKAction.animate(with: textureArray, timePerFrame: 0.1)))
}

func stopAnimation() {
    dog.removeAllActions()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}
}

This is my GameScene file:

import SpriteKit
import GameplayKit

class GameScene: SKScene {

var dog: Dog!

override func didMove(to view: SKView) {
    scene?.backgroundColor = UIColor(red: 132.0/255.0, green: 179.0/255.0, blue: 255.0/255.0, alpha: 1.0)

    addDog()

}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    dog.animate()
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
    dog.stopAnimation()
}

func addDog() {

    dog = Dog()
    dog.position = CGPoint(x: frame.size.width / 2, y: frame.size.height / 2)
    addChild(dog)
}

}

I think the problem is in the animate function in the sprite file.

I have tried everything I can think of. Any help would be greatly appreciated.


问:
How to pass the value of variable when next page loads in JavaScript?
I have a variable named collar whose value is either red or green. It is used for random order as on or off. But in next page,it wont retain its previous value. How to do that. I am beginner in JavaScript.</p>

答: You may find this answer useful.Maintaing state in JS. You may use cookies to store the value.


问:
Add custom attributes of layout to children
I have layout

```<code><android.support.v7.widget.GridLayout
    android:id="@+id/grid_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/default_grid_height"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!--I need add to this child attribute "app:layout_*"-->
    <Button
        android:text="1"
        app:layout_columnSpan="2"
        app:layout_columnWeight="2"
        app:layout_rowWeight="3"/>

</android.support.v7.widget.GridLayout>
</code>```

I need to programmatically add child to this layout container (support.v7.widget.GridLayout) with custom attributes supported by this layout. How i can do this?
Assume I can do something like that, but not found something method like tihs.

```<code>widget = CustomWidget(context)
widget.addParam("app:layout_rowWeight", 3) // how??
</code>```

答:
It isn't difficult to add something to GridLayout like this. But you need to know what do you want to add.

```<code>GridLayout gv = (GridLayout) findViewById(R.id.grid_layout);
TextView tv = new TextView(context);
tv.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
tv.setText("TextView");
LayoutParams params = new LayoutParams(Set your column and row information as params);
tv.setLayoutParams(params);
gv.addView(tv);
</code>```

Body:
I have layout

<android.support.v7.widget.GridLayout
    android:id="@+id/grid_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/default_grid_height"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <Button
        android:text="1"
        app:layout_columnSpan="2"
        app:layout_columnWeight="2"
        app:layout_rowWeight="3"/>

</android.support.v7.widget.GridLayout>

I need to programmatically add child to this layout container (support.v7.widget.GridLayout) with custom attributes supported by this layout. How i can do this?
Assume I can do something like that, but not found something method like tihs.

widget = CustomWidget(context)
widget.addParam("app:layout_rowWeight", 3) // how??

Body:
It isn't difficult to add something to GridLayout like this. But you need to know what do you want to add.

GridLayout gv = (GridLayout) findViewById(R.id.grid_layout);
TextView tv = new TextView(context);
tv.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
tv.setText("TextView");
LayoutParams params = new LayoutParams(Set your column and row information as params);
tv.setLayoutParams(params);
gv.addView(tv);


问:
how to write an extension for operator?
For example, write an extension for operator ">" to compare CGSize</p>

```<code>let sizeA = CGSize(...)
let sizeB = CGSize(...)
sizeA > sizeB // How to let operator ">" support CGSize
</code>```

答:
Simply define the > function for CGSize:

```<code>extension CGSize {
    static func > (_ lhs: CGSize, _ rhs: CGSize) -> Bool {
        // Implement as needed
        return lhs.width > rhs.width && lhs.height > rhs.height
    }
}
</code>```

Title: how to write an extension for operator?

Body:
For example, write an extension for operator ">" to compare CGSize

let sizeA = CGSize(...)
let sizeB = CGSize(...)
sizeA > sizeB // How to let operator ">" support CGSize

Body:
Simply define the > function for CGSize:

extension CGSize {
    static func > (_ lhs: CGSize, _ rhs: CGSize) -> Bool {
        // Implement as needed
        return lhs.width > rhs.width && lhs.height > rhs.height
    }
}


问:
Catching Java SQLExceptions
I do not have a lot of experience in Java and would appreciate if you bring a light on the question.

I have the following piece of code (method) to establish the JDBC connection with a PostgreSQL database :

```<code>public void establishDBConnection() throws SQLException {

    try (Connection connection = DriverManager.getConnection(
                "jdbc:postgresql://" + dbServer + ":" + dbPort + "/" +
                dbDatabase, dbUser, dbPassword))
    catch (SQLException e) {
        logger.error("Connection to Postgres Database Failed: " +
        e.printStackTrace();
    }
 }
</code>```

I expect that the SQLException would be caught by the catch block as soon as the method can't establish connection with the database (server is down). The catch block puts the exception on the console but I see that the same exception is displayed earlier right after the getConnection method execution. Thus, I have 2 quite the same exceptions on the console. See below.

The question is what is the reason for this and how to force the application to display only the exception generated by the catch block.

Logs:

```<code>Jul 07, 2017 9:11:53 PM org.postgresql.Driver connect
SEVERE: Connection error:
**org.postgresql.util.PSQLException: Connection to localhost:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.**
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:265)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
    at org.postgresql.Driver.makeConnection(Driver.java:431)
    at org.postgresql.Driver.connect(Driver.java:247)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at excel2db.service.impl.DBConnectionPostgresImpl.establishDBConnection(DBConnectionPostgresImpl.java:38)
    at excel2db.excel2db.main(excel2db.java:86)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:62)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)
    ... 13 more

21:11:53.465 [main] ERROR e.s.impl.DBConnectionPostgresImpl - **Connection to Postgres Database Failed: Connection to localhost:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.**
</code>```

答:
You need to load the driver's class into memory. Try This code :</p>
```<code>try {
    Class.forName("org.postgresql.Driver");

    Connection connection = DriverManager.getConnection(jdbc:postgresql://server_address:5432/database_name?user=usernam&password=password);

} catch (Exception exception) {
    exception.printStackTrace();
}
</code>```

Title: Catching Java SQLExceptions

Body:
I do not have a lot of experience in Java and would appreciate if you bring a light on the question.

I have the following piece of code (method) to establish the JDBC connection with a PostgreSQL database :

public void establishDBConnection() throws SQLException {

    try (Connection connection = DriverManager.getConnection(
                "jdbc:postgresql://" + dbServer + ":" + dbPort + "/" +
                dbDatabase, dbUser, dbPassword))
    catch (SQLException e) {
        logger.error("Connection to Postgres Database Failed: " +
        e.printStackTrace();
    }
 }

I expect that the SQLException would be caught by the catch block as soon as the method can't establish connection with the database (server is down). The catch block puts the exception on the console but I see that the same exception is displayed earlier right after the getConnection method execution. Thus, I have 2 quite the same exceptions on the console. See below.

The question is what is the reason for this and how to force the application to display only the exception generated by the catch block.

Logs:

Jul 07, 2017 9:11:53 PM org.postgresql.Driver connect
SEVERE: Connection error:
**org.postgresql.util.PSQLException: Connection to localhost:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.**
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:265)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
    at org.postgresql.Driver.makeConnection(Driver.java:431)
    at org.postgresql.Driver.connect(Driver.java:247)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at excel2db.service.impl.DBConnectionPostgresImpl.establishDBConnection(DBConnectionPostgresImpl.java:38)
    at excel2db.excel2db.main(excel2db.java:86)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at org.postgresql.core.PGStream.<init>(PGStream.java:62)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)
    ... 13 more

21:11:53.465 [main] ERROR e.s.impl.DBConnectionPostgresImpl - **Connection to Postgres Database Failed: Connection to localhost:5433 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.**

Body:
You need to load the driver's class into memory. Try This code :

try {
    Class.forName("org.postgresql.Driver");

    Connection connection = DriverManager.getConnection(jdbc:postgresql://server_address:5432/database_name?user=usernam&password=password);

} catch (Exception exception) {
    exception.printStackTrace();
}

ContentLicense: CC BY-SA 4.0


问:
How do i modify Linq generated sql statement?
I have summarized my problem in following code.

```<code>NorthwindDataContext dc = new NorthwindDataContext();
        var query = from c in dc.Customers
                    select c;
</code>```

Above code is generating following sql statement

```
    SELECT [t0].[ID], [t0].[FirstName], [t0].[LastName]
FROM [dbo].[Customer] AS [t0]
```

Now i want to modify the above generated query something like this

```
SELECT [t0].[ID], [t0].[FirstName], [t0].[LastName] FROM [dbo].[Customer]
AS [t0] WITH (nolock)
```

Is it possible in linq to modify the generated query?If yes then how?

答:
Maybe these pages will help you..

http://www.infoq.com/news/2008/03/linq-nolock

http://coolthingoftheday.blogspot.com/2008/03/linq-to-sql-nolock.html

which refers hanselmans blog entry

http://www.hanselman.com/blog/GettingLINQToSQLAndLINQToEntitiesToUseNOLOCK.aspx

or check out this question

NOLOCK with Linq to SQL

Body:
I have summarized my problem in following code.

NorthwindDataContext dc = new NorthwindDataContext();
        var query = from c in dc.Customers
                    select c;

Above code is generating following sql statement

    SELECT [t0].[ID], [t0].[FirstName], [t0].[LastName]
FROM [dbo].[Customer] AS [t0]

Now i want to modify the above generated query something like this

SELECT [t0].[ID], [t0].[FirstName], [t0].[LastName] FROM [dbo].[Customer]
AS [t0] WITH (nolock)

Is it possible in linq to modify the generated query?If yes then how?


答:
You need to use cookies, sessionStorage, localStorage, or query parameters.

Please take a look at these similar questions:

How to get JS variable to retain value after page refresh?

javascript passing variables to the next page (without php)

Global Variable usage on page reload

pass variable between php and javascript without load page

Passing variable when opening another html page using JavaScript

Pass a variable to new page

Maintaining state in javascript through html class

Passing value to JS function through URL on window load

Title: How to pass the value of variable when next page loads in JavaScript?

Body: I have a variable named collar whose value is either red or green. It is used for random order as on or off. But in next page,it wont retain its previous value. How to do that. I am beginner in JavaScript.


答:
You can extend CGSize to conform to Comparable protocol. @MartinR got the point. I updated my answer to compare the size as area comparison.

```<code>extension CGSize {
    public static func <(lhs: CGSize, rhs: CGSize) -> Bool {
        return (lhs.width * lhs.height) < (rhs.width * rhs.height)
    }

    public static func >(lhs: CGSize, rhs: CGSize) -> Bool {
        return (lhs.width * lhs.height) > (rhs.width * rhs.height)
    }
}
</code>```

Title: how to write an extension for operator?

Body:
You can extend CGSize to conform to Comparable protocol. @MartinR got the point. I updated my answer to compare the size as area comparison.

extension CGSize {
    public static func <(lhs: CGSize, rhs: CGSize) -> Bool {
        return (lhs.width * lhs.height) < (rhs.width * rhs.height)
    }

    public static func >(lhs: CGSize, rhs: CGSize) -> Bool {
        return (lhs.width * lhs.height) > (rhs.width * rhs.height)
    }
}


问:
Printing *s as triangles in Java?
My assignment in my Java course is to make 3 triangles. One left aligned, one right aligned, and one centered. I have to make a menu for what type of triangle and then input how many rows is wanted. The triangles have to look like this

```<code>*
**
***
****

   *
  **
 ***
****

  *
 ***
*****
</code>```

So far I was able to do the left aligned triangle but I can't seem to get the other two. I tried googling but nothing turned up. Can anyone help? I have this so far.

```<code>import java.util.*;
public class Prog673A
{
    public static void leftTriangle()
    {
        Scanner input = new Scanner (System.in);
        System.out.print("How many rows: ");
        int rows = input.nextInt();
        for (int x = 1; x <= rows; x++)
        {
            for (int i = 1; i <= x; i++)
            {
                System.out.print("*");
            }
            System.out.println("");
        }
    }
    public static void rightTriangle()
    {
        Scanner input = new Scanner (System.in);
        System.out.print("How many rows: ");
        int rows = input.nextInt();
        for (int x = 1; x <= rows; x++)
        {
            for (int i = 1; i >= x; i--)
            {
                System.out.print(" ");
            }
            System.out.println("*");
        }
    }
    public static void centerTriangle()
    {

    }
    public static void main (String args [])
    {
        Scanner input = new Scanner (System.in);
        System.out.println("Types of Triangles");
        System.out.println("\t1. Left");
        System.out.println("\t2. Right");
        System.out.println("\t3. Center");
        System.out.print("Enter a number: ");
        int menu = input.nextInt();
        if (menu == 1)
            leftTriangle();
        if (menu == 2)
            rightTriangle();
        if (menu == 3)
            centerTriangle();
    }
}
</code>```

Sample Output:

```<code>Types of Triangles
1.  Left
2.  Right
3.  Center
Enter a number (1-3):  3
How many rows?: 6

     *
    ***
   *****
  *******
 *********
***********
</code>```

答:
You might be interested in this too

```<code>      Scanner sc = new Scanner(System.in);
      int n=sc.nextInt();
      int b=0;
      for(int i=n;i>=1;i--){
      if(i!=n){
      for(int k=1;k<=b;k++){
      System.out.print(" ");
        }
            }
       for(int j=i;j>=1;j--){
       System.out.print("*");
       if(i!=1){
       System.out.print(" ");
        }
            }
       System.out.println();
       b=b+2;
        }
</code>```

Output::   5

```<code>       * * * * *
         * * * *
           * * *
             * *
               *
</code>```

Title: Printing *s as triangles in Java?

Body:
My assignment in my Java course is to make 3 triangles. One left aligned, one right aligned, and one centered. I have to make a menu for what type of triangle and then input how many rows is wanted. The triangles have to look like this

*
**
***
****

   *
  **
 ***
****

  *
 ***
*****

So far I was able to do the left aligned triangle but I can't seem to get the other two. I tried googling but nothing turned up. Can anyone help? I have this so far.

import java.util.*;
public class Prog673A
{
    public static void leftTriangle()
    {
        Scanner input = new Scanner (System.in);
        System.out.print("How many rows: ");
        int rows = input.nextInt();
        for (int x = 1; x <= rows; x++)
        {
            for (int i = 1; i <= x; i++)
            {
                System.out.print("*");
            }
            System.out.println("");
        }
    }
    public static void rightTriangle()
    {
        Scanner input = new Scanner (System.in);
        System.out.print("How many rows: ");
        int rows = input.nextInt();
        for (int x = 1; x <= rows; x++)
        {
            for (int i = 1; i >= x; i--)
            {
                System.out.print(" ");
            }
            System.out.println("*");
        }
    }
    public static void centerTriangle()
    {

    }
    public static void main (String args [])
    {
        Scanner input = new Scanner (System.in);
        System.out.println("Types of Triangles");
        System.out.println("\t1. Left");
        System.out.println("\t2. Right");
        System.out.println("\t3. Center");
        System.out.print("Enter a number: ");
        int menu = input.nextInt();
        if (menu == 1)
            leftTriangle();
        if (menu == 2)
            rightTriangle();
        if (menu == 3)
            centerTriangle();
    }
}

Sample Output:

Types of Triangles
1.  Left
2.  Right
3.  Center
Enter a number (1-3):  3
How many rows?: 6

     *
    ***
   *****
  *******
 *********
***********

Body:
You might be interested in this too

      Scanner sc = new Scanner(System.in);
      int n=sc.nextInt();
      int b=0;
      for(int i=n;i>=1;i--){
      if(i!=n){
      for(int k=1;k<=b;k++){
      System.out.print(" ");
        }
            }
       for(int j=i;j>=1;j--){
       System.out.print("*");
       if(i!=1){
       System.out.print(" ");
        }
            }
       System.out.println();
       b=b+2;
        }

Output::   5

       * * * * *
         * * * *
           * * *
             * *
               *


问:
Codeigniter 3 - how to remove the function name from URL
My URL is:

```<code>example.com/controller/function/parameter
=> example.com/category/index/category_name
</code>```

I need:

```<code>example.com/category/category_name
</code>```

I have tried several solutions provided by Stackoverflow questions asked on this, but it´s not working. Either it redirects to home or a 404 page not found.

The options I have tried are:

```<code>$route['category'] = "category/index"; //1

$route['category/(:any)'] = "category/index"; //2

$route['category/(:any)'] = "category/index/$1";  //3
</code>```

Another route is:

```<code>$route['default_controller'] = 'home';
</code>```

The htaccess file:

```<code>RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</code>```

In config file I have:

```<code>$config['url_suffix'] = '';
</code>```

答:
I think you have error in your .htaccess file. Please find below code for .htaccess file.

You can use RewriteBase to provide a base for your rewrites.

```<code>RewriteEngine On
RewriteBase /campnew/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</code>```

In Controller your method.

```<code>public function index($category_name = null) {
    $this->load->model('category_model');

    $data = array();

    if ($query = $this->category_model->get_records_view($category_name)) {
        $data['recordss'] = $query;
    }
    if ($query2 = $this->category_model->get_records_view2($category_name))
    {
        $data['recordsc2'] = $query2;
    }

    $data['main_content'] = 'category';
    $this->load->view('includes/template', $data);
}
</code>```

In Model File

```<code>public function get_records_view($category){
    $this->db->where('a.linkname', $category);
}
</code>```

Let me know if it not works.

Body:
My URL is:

example.com/controller/function/parameter
=> example.com/category/index/category_name

I need:

example.com/category/category_name

I have tried several solutions provided by Stackoverflow questions asked on this, but it´s not working. Either it redirects to home or a 404 page not found.

The options I have tried are:

$route['category'] = "category/index"; //1

$route['category/(:any)'] = "category/index"; //2

$route['category/(:any)'] = "category/index/$1";  //3

Another route is:

$route['default_controller'] = 'home';

The htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

In config file I have:

$config['url_suffix'] = '';

Body:
I think you have error in your .htaccess file. Please find below code for .htaccess file.

You can use RewriteBase to provide a base for your rewrites.

RewriteEngine On
RewriteBase /campnew/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]

In Controller your method.

public function index($category_name = null) {
    $this->load->model('category_model');

    $data = array();

    if ($query = $this->category_model->get_records_view($category_name)) {
        $data['recordss'] = $query;
    }
    if ($query2 = $this->category_model->get_records_view2($category_name))
    {
        $data['recordsc2'] = $query2;
    }

    $data['main_content'] = 'category';
    $this->load->view('includes/template', $data);
}

In Model File

public function get_records_view($category){
    $this->db->where('a.linkname', $category);
}

Let me know if it not works.


问:
How do I force a sign-character on the output of an NSNumberFormatter
I want to use a number formatter to generate my output, so the number is automatically formatted for the user's locale, but I want it to work like "%+.1f" does in printf(), that is always have a sign specified.

```<code>NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
nf.numberStyle = NSNumberFormatterDecimalStyle;
nf.maximumFractionDigits = 1;

double val = 3.1234;
label.text = [NSString stringWithFormat: @"XXX %@ XXX", [nf stringFromNumber: [NSNumber numberWithDouble: val]]];
</code>```

I want the label to come out "XXX +3.1 XXX" in the US and the appropriate but equivalent string for any other location. The only things I can find are setPositiveFormat: and setPositivePrefix:.

But I don't want to set the format since I don't know how to format numbers in other countries; I don't know if a plus-sign is used to designate a positive number in Arabic or Russian or some culture I have not thought of. I do know, for example, that decimal points, commas, spaces, etc., all have different meanings in European countries compared to the U.S. - Could the same be true for +/- signs?

What I do currently is:

```<code>label.text = [NSString stringWithFormat: @"XXX %s%@ XXX", (val < 0) ? "" : "+",
    [nf stringFromNumber: [NSNumber numberWithDouble: val]]];
</code>```

But this presumes that '+' and '-' are correct for all formats.

I'm sure it must be there since it is a standard formatting thing that has been in printf() since the dark ages...

答:
Simple Case:

```<code>    let f = NumberFormatter()
    f.positivePrefix = f.plusSign
</code>```

Currency Case :

Hack needed, because setting the prefix to plusSign only will remove the currency symbol.

```<code>    let f = NumberFormatter()
    f.numberStyle = .currency
    f.positivePrefix = f.plusSign + f.currencySymbol
</code>```

There is a bit more work depending on the locale.. The currency symbol may be before, or after, but this is probably another subject..

Edit:

Even if it is another subject, I'd say a possible solution to the problem above is to subclass NSNumberFormatter :

```<code>override func string(from number: NSNumber) -> String? {
    returns ( number.doubleValue >= 0 ? super.plusSign : "" ) + super.string(from: number)
}
</code>```

This way, NSNumberFormatter should manage the currency position while your subclass simply prepend the + sign. No time to test this in depth, but at least it is an approach.

Body:
I want to use a number formatter to generate my output, so the number is automatically formatted for the user's locale, but I want it to work like "%+.1f" does in printf(), that is always have a sign specified.

NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
nf.numberStyle = NSNumberFormatterDecimalStyle;
nf.maximumFractionDigits = 1;

double val = 3.1234;
label.text = [NSString stringWithFormat: @"XXX %@ XXX", [nf stringFromNumber: [NSNumber numberWithDouble: val]]];

I want the label to come out "XXX +3.1 XXX" in the US and the appropriate but equivalent string for any other location. The only things I can find are setPositiveFormat: and setPositivePrefix:.

But I don't want to set the format since I don't know how to format numbers in other countries; I don't know if a plus-sign is used to designate a positive number in Arabic or Russian or some culture I have not thought of. I do know, for example, that decimal points, commas, spaces, etc., all have different meanings in European countries compared to the U.S. - Could the same be true for +/- signs?

What I do currently is:

label.text = [NSString stringWithFormat: @"XXX %s%@ XXX", (val < 0) ? "" : "+",
    [nf stringFromNumber: [NSNumber numberWithDouble: val]]];

But this presumes that '+' and '-' are correct for all formats.

I'm sure it must be there since it is a standard formatting thing that has been in printf() since the dark ages...

Body:
Simple Case:

    let f = NumberFormatter()
    f.positivePrefix = f.plusSign

Currency Case :

Hack needed, because setting the prefix to plusSign only will remove the currency symbol.

    let f = NumberFormatter()
    f.numberStyle = .currency
    f.positivePrefix = f.plusSign + f.currencySymbol

There is a bit more work depending on the locale.. The currency symbol may be before, or after, but this is probably another subject..

Edit:

Even if it is another subject, I'd say a possible solution to the problem above is to subclass NSNumberFormatter :

override func string(from number: NSNumber) -> String? {
    returns ( number.doubleValue >= 0 ? super.plusSign : "" ) + super.string(from: number)
}

This way, NSNumberFormatter should manage the currency position while your subclass simply prepend the + sign. No time to test this in depth, but at least it is an approach.


问:
iOS Background Audio Icon
I've followed the API Docs and WWDC Videos exactly, to play audio in the background via an Audio Session (using the AudioQueue services). It all works just fine, but there is no "Play" indicator displayed in the Status Bar.

Do i have to set this separately or is it a Bug?

答:
I think this was done by the Audio Session:</p>

```<code>// before instantiating the playback audio queue object,
//  set the audio session category
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (
                         kAudioSessionProperty_AudioCategory,
                         sizeof (sessionCategory),
                         &sessionCategory
                         );

// activate the audio session immmediately before playback starts
AudioSessionSetActive (true);
</code>```

Title: iOS Background Audio Icon

Body:
I think this was done by the Audio Session:

// before instantiating the playback audio queue object,
//  set the audio session category
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (
                         kAudioSessionProperty_AudioCategory,
                         sizeof (sessionCategory),
                         &sessionCategory
                         );

// activate the audio session immmediately before playback starts
AudioSessionSetActive (true);


问:
Update multiple columns in a database using meta keys and meta values
am trying to update multiple fields in a database using their respective meta key but it doesn't work. It works only when I update them one at a time. How do I it to update multiple fields?

Below works:

```<code>$sql = "UPDATE wp_usermeta SET meta_value = '$meta_value' WHERE meta_key = '$meta_key' AND user_id= $user_ID";
</code>```

Below does not work:

```<code>$sql = "UPDATE wp_usermeta SET (meta_value = '$meta_value', meta_key = '$meta_key'), (meta_value = 'The freak I wants', meta_key = 'on_the_weekends_i' WHERE user_id= $user_id)";
</code>```

答:
Please try this : </p>

```<code>    $metaInfo= [
         [
            'meta_key'=>$meta_key,
            'meta_value'=>$meta_value,

          ],
          [
            'meta_key'=>'another key',
            'meta_value'=>'another value',

          ],
          [
            'meta_key'=>'another key 1',
            'meta_value'=>'another value 1',

          ]
        ];

        foreach($metaInfo as $info){
          foreach($info as $field => $value){
            $sql= "UPDATE wp_usermeta SET ($field='$value') WHERE user_id=$user_id";
           //execute here your query
            }

        }
</code>```

Body:
am trying to update multiple fields in a database using their respective meta key but it doesn't work. It works only when I update them one at a time. How do I it to update multiple fields?

Below works:

$sql = "UPDATE wp_usermeta SET meta_value = '$meta_value' WHERE meta_key = '$meta_key' AND user_id= $user_ID";

Below does not work:

$sql = "UPDATE wp_usermeta SET (meta_value = '$meta_value', meta_key = '$meta_key'), (meta_value = 'The freak I wants', meta_key = 'on_the_weekends_i' WHERE user_id= $user_id)";

Body:
Please try this :

    $metaInfo= [
         [
            'meta_key'=>$meta_key,
            'meta_value'=>$meta_value,

          ],
          [
            'meta_key'=>'another key',
            'meta_value'=>'another value',

          ],
          [
            'meta_key'=>'another key 1',
            'meta_value'=>'another value 1',

          ]
        ];

        foreach($metaInfo as $info){
          foreach($info as $field => $value){
            $sql= "UPDATE wp_usermeta SET ($field='$value') WHERE user_id=$user_id";
           //execute here your query
            }

        }


问:
User-ID view not populating even though I am following all the right steps
Folks,
I have looked high and low but seem to be totally stymied now. To capture login-ID as userID in Google Analytics, we have done the following
1. Create a userID view in GA(Google Analytics)
2. Create a custom dimension in GA
3. Add a Data layer variable in Google Tag Manager(GTM)called userID
4. Add the variable as fields to be set within the "fields to Set". Also added the custom dimension as a field to be set.

When I publish the tag, the User-ID view stays stubbornly unpopulated. I have tested and the dataLayer variable is showing up fine in the preview mode.

I have defined userID be uniform throughout with the same upper and lower case spelling. However, in other instructions on how to do this https://www.clickinsight.ca/about/blog/implement-user-id-tracking
they have changed the case of the variable. Does the variable name need to be a particular way for Google Analytics to capture the data?

Any help is welcome. Thanks in advance.

答:
The custom dimension is not actually necessary. Google Analytics does not expose the userId via the interface, so you may add a custom dimension if you want to use it in the reports, but the userId view works without it.

The tutorial you linked is a bit confusing since they use a different case for the GTM variable (userID) and the GA field (userId). While this is technically correct it would probably be easier if they used a unified spelling (casing ?).

The field name for the field that needs to be set in Google Analytics is userId (capital "i", small "d") per the analytics.js field reference (the tutorial has it correctly in its screen shots, but again you might have gotten confused by the different spellings in the text).


问:
How do for statements work in jQuery?
I am currently using this code for my project but I can help but to feel a for statement could be used instead.

```<code>$("#login-1").text($("#" + iconId).data("login1"));
$("#login-1").click(function() {
   var send='';
   send += $("#" + iconId).data("name")+"</br>";
   send += $("#" + iconId).data("login1")+"</br>";
   send += $("#" + iconId).data("username1")+"</br>";
   send += $("#" + iconId).data("password1")+"</br>";
   $("#post").html(send);
   cancel();
});

$("#login-2").text($("#" + iconId).data("login2"));
$("#login-2").click(function() {
   var send='';
   send += $("#" + iconId).data("name")+"</br>";
   send += $("#" + iconId).data("login2")+"</br>";
   send += $("#" + iconId).data("username2")+"</br>";
   send += $("#" + iconId).data("password2")+"</br>";
   $("#post").html(send);
   cancel();
});

$("#login-3").text($("#" + iconId).data("login3"));
$("#login-3").click(function() {
   var send='';
   send += $("#" + iconId).data("name")+"</br>";
   send += $("#" + iconId).data("login3")+"</br>";
   send += $("#" + iconId).data("username3")+"</br>";
   send += $("#" + iconId).data("password3")+"</br>";
   $("#post").html(send);
   cancel();
});
</code>```

The only thing changing in between most of the lines of code are the number on login# username# password#

答:
You could use:

```<code>$("#login-1,#login-2,#login-3").click(function(){
    ...
});
</code>```

And change the code inside based on $(this).

Title: How do for statements work in jQuery?

Body:
I am currently using this code for my project but I can help but to feel a for statement could be used instead.

$("#login-1").text($("#" + iconId).data("login1"));
$("#login-1").click(function() {
   var send='';
   send += $("#" + iconId).data("name")+"
";
   send += $("#" + iconId).data("login1")+"
";
   send += $("#" + iconId).data("username1")+"
";
   send += $("#" + iconId).data("password1")+"
";
   $("#post").html(send);
   cancel();
});

$("#login-2").text($("#" + iconId).data("login2"));
$("#login-2").click(function() {
   var send='';
   send += $("#" + iconId).data("name")+"
";
   send += $("#" + iconId).data("login2")+"
";
   send += $("#" + iconId).data("username2")+"
";
   send += $("#" + iconId).data("password2")+"
";
   $("#post").html(send);
   cancel();
});

$("#login-3").text($("#" + iconId).data("login3"));
$("#login-3").click(function() {
   var send='';
   send += $("#" + iconId).data("name")+"
";
   send += $("#" + iconId).data("login3")+"
";
   send += $("#" + iconId).data("username3")+"
";
   send += $("#" + iconId).data("password3")+"
";
   $("#post").html(send);
   cancel();
});

The only thing changing in between most of the lines of code are the number on login# username# password#

Body:
You could use:

$("#login-1,#login-2,#login-3").click(function(){
    ...
});

And change the code inside based on $(this).


问:
Entity Framework does not update column after changing value of column in SQL Server
I am using Entity Framework 6. When I update a column of the database using EF. The record will update without any problem, but after I change the value of the column in SQL Server using update query EF does not update column value and does not throw any exception.

```<code>CustomerMandate customerMandate = await DbContext.CustomerMandates.FirstOrDefaultAsync(mandate => mandate.Id == 1, cancellationToken);
if (customerMandate != null)
{
    customerMandate.State = newState;
    await DbContext.SaveChangesAsync(cancellationToken);// not working
}

DbContext newContext = new DbContext();
CustomerMandate customerMandate1 = await newContext.CustomerMandates.FirstOrDefaultAsync(mandate => mandate.Id == 1, cancellationToken);
if (customerMandate1 != null)
{
    customerMandate1.State = newState;
    await DbContext.SaveChangesAsync(cancellationToken);// working
}
</code>```

in normal execute of application update is ok but when i change value in database using T-SQL DbContext.ChangeTracker.HasChanges() return false but when i create new Context and get record from DB and change it DbContext.ChangeTracker.HasChanges()  return true
Any ideas?

答:
Probably you are trying to simulate situation of concurrent access. If yes, then please put break point at line

```<code>if (customerMandate != null)
</code>```

Now, modify value in database and move ahead from the break-point. You would expect exception at SaveChangesAsync call.

Another think you can check is modify state in table using TSQL in management studio and then very if you new state was available in customerMandate when you run your program next time.

We cannot see where DbContext is defined and used before using it in line#1 of shared code. I hope you have made sure that any pending items/actions pending on that DbContext were completed before starting another update query. If not then those can cause failure.

Body:
I am using Entity Framework 6. When I update a column of the database using EF. The record will update without any problem, but after I change the value of the column in SQL Server using update query EF does not update column value and does not throw any exception.

CustomerMandate customerMandate = await DbContext.CustomerMandates.FirstOrDefaultAsync(mandate => mandate.Id == 1, cancellationToken);
if (customerMandate != null)
{
    customerMandate.State = newState;
    await DbContext.SaveChangesAsync(cancellationToken);// not working
}

DbContext newContext = new DbContext();
CustomerMandate customerMandate1 = await newContext.CustomerMandates.FirstOrDefaultAsync(mandate => mandate.Id == 1, cancellationToken);
if (customerMandate1 != null)
{
    customerMandate1.State = newState;
    await DbContext.SaveChangesAsync(cancellationToken);// working
}

in normal execute of application update is ok but when i change value in database using T-SQL DbContext.ChangeTracker.HasChanges() return false but when i create new Context and get record from DB and change it DbContext.ChangeTracker.HasChanges()  return true
Any ideas?

Body:
Probably you are trying to simulate situation of concurrent access. If yes, then please put break point at line

if (customerMandate != null)

Now, modify value in database and move ahead from the break-point. You would expect exception at SaveChangesAsync call.

Another think you can check is modify state in table using TSQL in management studio and then very if you new state was available in customerMandate when you run your program next time.

We cannot see where DbContext is defined and used before using it in line#1 of shared code. I hope you have made sure that any pending items/actions pending on that DbContext were completed before starting another update query. If not then those can cause failure.


问:
PayPal's CallerServices Works on localhost but not server
My PayPal Direct script works perfect on my machine. Both nUnit tests and via a website on localhost. However this first line of code fails on my server and another server. (both full trust)

```<code>CallerServices caller = new CallerServices();
</code>```

Message: The type initializer for 'com.paypal.sdk.core.soap.SOAPAPICaller' threw an exception.
Source: paypal_base

Stack Trace:

at com.paypal.sdk.core.soap.SOAPAPICaller..ctor()
   at com.paypal.sdk.services.CallerServices..ctor()
   at TS.Common.BusinessLogic.PaymentGateways.PayPalProController.CChargeCard(String paymentAmount, Order CurrentOrder, String creditCardType, String creditCardNumber, String CVV2, String expMonth, String expYear, PaymentActionCodeType paymentAction, Transaction& transaction)
   at TS.Common.BusinessLogic.PaymentGateways.PayPalProController.ChargeCard(Order CurrentOrder, Decimal Amount, String CreditCardNum, String ExpMonth, String ExpYear, String SecurityNumber, Transaction& transaction)
   at OrderController.SubmitCreditCardPayment(Order order, Decimal ChargeAmount, String CreditCardNum, String ExpMonth, String ExpYear, String Var, String CardType, Transaction& transaction)
   at OrderController.SubmitOrder(Order order, Transaction& transaction, Nullable`1 GiftCertId, String CreditCardNum, String ExpMonth, String ExpYear, String Var, String CardType, String Culture)
   at Checkout.btnOrder_Click(Object sender, EventArgs e) in d:\Inetpub\tickets\Checkout.aspx.cs:line 488

答: Add log4net.dll , if not put it in your bin folder and add reference. It works for me...</p>

Body:
My PayPal Direct script works perfect on my machine. Both nUnit tests and via a website on localhost. However this first line of code fails on my server and another server. (both full trust)

CallerServices caller = new CallerServices();

Message: The type initializer for 'com.paypal.sdk.core.soap.SOAPAPICaller' threw an exception.
Source: paypal_base

Stack Trace:

at com.paypal.sdk.core.soap.SOAPAPICaller..ctor()
   at com.paypal.sdk.services.CallerServices..ctor()
   at TS.Common.BusinessLogic.PaymentGateways.PayPalProController.CChargeCard(String paymentAmount, Order CurrentOrder, String creditCardType, String creditCardNumber, String CVV2, String expMonth, String expYear, PaymentActionCodeType paymentAction, Transaction& transaction)
   at TS.Common.BusinessLogic.PaymentGateways.PayPalProController.ChargeCard(Order CurrentOrder, Decimal Amount, String CreditCardNum, String ExpMonth, String ExpYear, String SecurityNumber, Transaction& transaction)
   at OrderController.SubmitCreditCardPayment(Order order, Decimal ChargeAmount, String CreditCardNum, String ExpMonth, String ExpYear, String Var, String CardType, Transaction& transaction)
   at OrderController.SubmitOrder(Order order, Transaction& transaction, Nullable`1 GiftCertId, String CreditCardNum, String ExpMonth, String ExpYear, String Var, String CardType, String Culture)
   at Checkout.btnOrder_Click(Object sender, EventArgs e) in d:\Inetpub\tickets\Checkout.aspx.cs:line 488


答:
Just to overload the operator >

```<code>extension CGSize{
    static func >(_ left: CGSize, _ right: CGSize)->Bool{
        return left.width*left.height > right.width*right.height
    }
}
</code>```

Title: how to write an extension for operator?

Body:
For example, write an extension for operator ">" to compare CGSize

let sizeA = CGSize(...)
let sizeB = CGSize(...)
sizeA > sizeB // How to let operator ">" support CGSize

Body:
Just to overload the operator >

extension CGSize{
    static func >(_ left: CGSize, _ right: CGSize)->Bool{
        return left.width*left.height > right.width*right.height
    }
}


问:
onFocus doesn't trigger showing and hide list item
Any clue what's wrong in my code? my onFocus event doesn't work on a div

```<code>class Hello extends React.Component {
  state = {
    openDropdown: false
  }
  toggleDropdown = () => {
  alert('x')
    this.setState({
        openDropdown: !this.state.openDropdown
    })
  }
  render() {
    return (
      <div>
        <div onFocus={this.toggleDropdown} onBlur={this.toggleDropdown}>
          MyList
        </div>
        <ul className={this.state.openDropdown ? 'show' : 'hide'}>
          <li>abc</li>
          <li>123</li>
          <li>xyz</li>
        </ul>
      </div>
    );
  }
}
</code>```

http://jsfiddle.net/sua5j29b/

There's another problem in this approach, how can I close the dropdown when I click on one of the list? If I change the state of openDropdown, the behavior can be ruined.

答:
To apply onFocus or onBlur on a div I have to use

tabIndex='0' on the div

Body:
Any clue what's wrong in my code? my onFocus event doesn't work on a div

class Hello extends React.Component {
  state = {
    openDropdown: false
  }
  toggleDropdown = () => {
  alert('x')
    this.setState({
        openDropdown: !this.state.openDropdown
    })
  }
  render() {
    return (

          MyList

abc

123

xyz

    );
  }
}

http://jsfiddle.net/sua5j29b/

There's another problem in this approach, how can I close the dropdown when I click on one of the list? If I change the state of openDropdown, the behavior can be ruined.


问:
How to get a json file in Angular 2 using the Http class?
I am trying to get a json file using the Http class in Angular 2. I followed the example on the Angular 2 homepage: https://angular.io/docs/js/latest/api/http/Http-class.html.
However, I am getting the error message below. I am using Angular 2.0.0-alpha.37, traceur 0.0.91, systemjs 0.16.11, es6-module-loader 0.16.6 and typescript 1.6.2. Any ideas on what might be wrong here?

app.ts

```<code>///<reference path="typings/angular2/angular2.d.ts"/>
///<reference path="typings/angular2/http.d.ts"/>
import {Component, View, bootstrap} from 'angular2/angular2';
import {Http, HTTP_BINDINGS} from 'angular2/http';

@Component({
  selector: 'myApp',
  viewBindings: [HTTP_BINDINGS]
})
@View({
  templateUrl: 'myapp.html'
})
class MyComponent {
  data: Object;
  constructor(http: Http) {
    http.get('data.json').toRx().map(res => res.json()).subscribe(data => this.data = data);
  }
}
bootstrap(MyComponent);
</code>```

index.html

```<code><!DOCTYPE html>
<html>
  <head>
    <script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
    <script src="../node_modules/angular2/bundles/http.dev.js"></script>
    <script src="../node_modules/traceur/bin/traceur-runtime.js"></script>
    <script src="../node_modules/es6-module-loader/dist/es6-module-loader.js"></script>
    <script src="../node_modules/systemjs/dist/system.src.js"></script>
  </head>
  <body>
    <myApp></myApp>
    <script>
      System.import('app');
    </script>
  </body>
</html>
</code>```

Result

```<code>EXCEPTION: Error during instantiation of MyComponent!.
EXCEPTION: Error during instantiation of MyComponent!.
ORIGINAL EXCEPTION: TypeError: Rx.Subject is not a function
ORIGINAL STACKTRACE:
TypeError: Rx.Subject is not a function
    at new EventEmitter (angular2.dev.js:22672)
    at new XHRConnection (http.dev.js:7474)
    at XHRBackend.createConnection (http.dev.js:7519)
    at httpRequest (http.dev.js:7291)
    at Http.get (http.dev.js:7369)
    at new MyComponent (:8080/src/app.js:19)
    at angular2.dev.js:8937
    at Injector._proto._instantiate (angular2.dev.js:28045)
    at Injector._proto._new (angular2.dev.js:27985)
    at InjectorInlineStrategy.protoStrategy.instantiateBinding (angular2.dev.js:27774)
ERROR CONTEXT:
_Context
EXCEPTION: TypeError: Cannot read property 'location' of undefined
EXCEPTION: TypeError: Cannot read property 'location' of undefined
STACKTRACE:
TypeError: Cannot read property 'location' of undefined
    at angular2.dev.js:27298
    at Zone.run (angular2.dev.js:136)
    at Zone.run (angular2.dev.js:16593)
    at zoneBoundFn (angular2.dev.js:109)
    at lib$es6$promise$$internal$$tryCatch (angular2.dev.js:1419)
    at lib$es6$promise$$internal$$invokeCallback (angular2.dev.js:1431)
    at lib$es6$promise$$internal$$publish (angular2.dev.js:1402)
    at angular2.dev.js:187
    at microtask (angular2.dev.js:16619)
    at Zone.run (angular2.dev.js:136)
EXCEPTION: TypeError: Cannot read property 'hostView' of undefined
EXCEPTION: TypeError: Cannot read property 'hostView' of undefined
STACKTRACE:
TypeError: Cannot read property 'hostView' of undefined
    at zone.run.tick (angular2.dev.js:27331)
    at Zone.run (angular2.dev.js:136)
    at Zone.run (angular2.dev.js:16593)
    at zoneBoundFn (angular2.dev.js:109)
    at lib$es6$promise$$internal$$tryCatch (angular2.dev.js:1419)
    at lib$es6$promise$$internal$$invokeCallback (angular2.dev.js:1431)
    at lib$es6$promise$$internal$$publish (angular2.dev.js:1402)
    at angular2.dev.js:187
    at microtask (angular2.dev.js:16619)
    at Zone.run (angular2.dev.js:136)
</code>```

答:
If you want to read .json file using http get method in angular 2 its depend on you using build tools.

Like if you using angular-cli then you need to put .json file inside assets folder and try to read that file like

```<code>http.get('<your file path inside assets folder>.json')
</code>```

But if you using webpack then you need to put that same .json file inside public folder

```<code>http.get('<your file path inside assets folder>.json')
</code>```

It will work

Body:
I am trying to get a json file using the Http class in Angular 2. I followed the example on the Angular 2 homepage: https://angular.io/docs/js/latest/api/http/Http-class.html.
However, I am getting the error message below. I am using Angular 2.0.0-alpha.37, traceur 0.0.91, systemjs 0.16.11, es6-module-loader 0.16.6 and typescript 1.6.2. Any ideas on what might be wrong here?

app.ts

///<reference path="typings/angular2/angular2.d.ts"/>
///<reference path="typings/angular2/http.d.ts"/>
import {Component, View, bootstrap} from 'angular2/angular2';
import {Http, HTTP_BINDINGS} from 'angular2/http';

@Component({
  selector: 'myApp',
  viewBindings: [HTTP_BINDINGS]
})
@View({
  templateUrl: 'myapp.html'
})
class MyComponent {
  data: Object;
  constructor(http: Http) {
    http.get('data.json').toRx().map(res => res.json()).subscribe(data => this.data = data);
  }
}
bootstrap(MyComponent);

index.html

<!DOCTYPE html>

    <myApp></myApp>

Result

EXCEPTION: Error during instantiation of MyComponent!.
EXCEPTION: Error during instantiation of MyComponent!.
ORIGINAL EXCEPTION: TypeError: Rx.Subject is not a function
ORIGINAL STACKTRACE:
TypeError: Rx.Subject is not a function
    at new EventEmitter (angular2.dev.js:22672)
    at new XHRConnection (http.dev.js:7474)
    at XHRBackend.createConnection (http.dev.js:7519)
    at httpRequest (http.dev.js:7291)
    at Http.get (http.dev.js:7369)
    at new MyComponent (:8080/src/app.js:19)
    at angular2.dev.js:8937
    at Injector._proto._instantiate (angular2.dev.js:28045)
    at Injector._proto._new (angular2.dev.js:27985)
    at InjectorInlineStrategy.protoStrategy.instantiateBinding (angular2.dev.js:27774)
ERROR CONTEXT:
_Context
EXCEPTION: TypeError: Cannot read property 'location' of undefined
EXCEPTION: TypeError: Cannot read property 'location' of undefined
STACKTRACE:
TypeError: Cannot read property 'location' of undefined
    at angular2.dev.js:27298
    at Zone.run (angular2.dev.js:136)
    at Zone.run (angular2.dev.js:16593)
    at zoneBoundFn (angular2.dev.js:109)
    at lib$es6$promise$$internal$$tryCatch (angular2.dev.js:1419)
    at lib$es6$promise$$internal$$invokeCallback (angular2.dev.js:1431)
    at lib$es6$promise$$internal$$publish (angular2.dev.js:1402)
    at angular2.dev.js:187
    at microtask (angular2.dev.js:16619)
    at Zone.run (angular2.dev.js:136)
EXCEPTION: TypeError: Cannot read property 'hostView' of undefined
EXCEPTION: TypeError: Cannot read property 'hostView' of undefined
STACKTRACE:
TypeError: Cannot read property 'hostView' of undefined
    at zone.run.tick (angular2.dev.js:27331)
    at Zone.run (angular2.dev.js:136)
    at Zone.run (angular2.dev.js:16593)
    at zoneBoundFn (angular2.dev.js:109)
    at lib$es6$promise$$internal$$tryCatch (angular2.dev.js:1419)
    at lib$es6$promise$$internal$$invokeCallback (angular2.dev.js:1431)
    at lib$es6$promise$$internal$$publish (angular2.dev.js:1402)
    at angular2.dev.js:187
    at microtask (angular2.dev.js:16619)
    at Zone.run (angular2.dev.js:136)

Body:
If you want to read .json file using http get method in angular 2 its depend on you using build tools.

Like if you using angular-cli then you need to put .json file inside assets folder and try to read that file like

http.get('<your file path inside assets folder>.json')

But if you using webpack then you need to put that same .json file inside public folder

http.get('<your file path inside assets folder>.json')

It will work


答:
You need to help python break the line correctly:

```<code>self.who += self.lr * numpy.dot
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs))
</code>```

python "breaks the line" after numpy.dot because it has no cue that the line goes further.

On the other hand, when you print:

```<code>print (numpy.dot
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs)))
</code>```

The entire expressin is in parentheses, so python knows to read it fully.

Solution:

You can either place your expression in parentheses:

```<code> self.who += (self.lr * numpy.dot
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs)))
</code>```

Or, add an indication for python to continue reading the line

```<code>self.who += self.lr * numpy.dot \
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs))
</code>```

For more information see this thread.

Title: Can't use * operand for the result of numpy.dot

Body:
I am using python3 and jupyter notebook

self.who += self.lr * numpy.dot
        ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs))

this code shows errors below

TypeError: unsupported operand type(s) for *: 'float' and 'builtin_function_or_method'

I try to check the later part of this sentence

print (numpy.dot
        ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs)))

it shows correct matrix.

Why does this error happen?

[[ -1.43954649e-01  -6.16570817e-02  -7.50716509e-02  -5.26743548e-02
   -1.33602408e-01  -8.66191231e-02  -1.82448447e-03  -1.14619563e-01
   -2.31254191e-03  -1.25371046e-01  -6.58786989e-03  -2.51314122e-02
   -9.03342766e-03  -1.38359348e-02  -7.51453146e-02  -1.23144972e-01
   -1.10367906e-01  -4.96956932e-03  -1.07926267e-01  -1.30058539e-01
   -1.01781919e-01  -8.43032061e-04  -1.26695656e-01  -2.48998290e-02
   -1.24699147e-01  -1.41539201e-01  -1.17165171e-01  -3.75355704e-02
   -5.87039591e-02  -1.26151940e-01  -1.19498873e-01  -1.34517700e-01
   -8.14579022e-03  -3.28206127e-02  -4.75840077e-02  -1.17981918e-02
   -1.44620195e-01  -1.10927695e-03  -1.41479266e-01  -1.30649564e-01
   -4.30125241e-03  -1.35096429e-01  -6.05816058e-02  -1.10157321e-01
   -4.47267308e-02  -7.28279212e-02  -5.31360471e-02  -7.78219707e-02
   -1.71757937e-02  -1.44978996e-01  -1.72653895e-02  -1.07254954e-01
   -9.32763127e-04  -1.05262485e-01  -5.99327953e-02  -4.50893988e-03
   -1.44377058e-01  -2.10525894e-04  -4.94344180e-02  -1.30978698e-01
   -6.83022164e-02  -9.27788252e-02  -1.30111840e-01  -1.45624062e-02
   -1.44733983e-01  -1.44224232e-01  -1.46240068e-02  -3.29418289e-02
   -1.39345845e-01  -5.91389063e-02  -2.65144914e-02  -2.98560477e-04
   -7.17849540e-02  -1.77096383e-02  -1.24107579e-01  -5.84745887e-02
   -1.33140055e-01  -2.85366904e-03  -1.55459756e-02  -3.29575928e-02
   -1.19938740e-01  -3.90768941e-02  -1.37363861e-01  -3.38880149e-02
   -1.28913856e-01  -2.04071240e-02  -6.59530207e-02  -7.50348109e-02
   -1.01345369e-03  -8.10496965e-02  -1.18090253e-01  -3.30326197e-03
   -4.18706215e-03  -8.62360279e-04  -1.70682515e-02  -1.08036311e-01
   -6.44866478e-03  -5.27289173e-02  -5.98901752e-03  -2.01450649e-02]
 [ -1.25811295e-01  -5.38861190e-02  -6.56099803e-02  -4.60355319e-02
   -1.16763801e-01  -7.57020645e-02  -1.59453521e-03  -1.00173463e-01
   -2.02108023e-03  -1.09569881e-01  -5.75756638e-03  -2.19639696e-02
   -7.89489779e-03  -1.20921200e-02  -6.56743598e-02  -1.07624371e-01
   -9.64576652e-02  -4.34322865e-03  -9.43237581e-02  -1.13666585e-01
   -8.89538146e-02  -7.36780345e-04  -1.10727544e-01  -2.17615740e-02
   -1.08982665e-01  -1.23700279e-01  -1.02398235e-01  -3.28047673e-02
   -5.13051938e-02  -1.10252355e-01  -1.04437809e-01  -1.17563735e-01
   -7.11913391e-03  -2.86840602e-02  -4.15867477e-02  -1.03112043e-02
   -1.26392959e-01  -9.69469008e-04  -1.23647898e-01  -1.14183120e-01
   -3.75914319e-03  -1.18069524e-01  -5.29461909e-02  -9.62736212e-02
   -3.90895883e-02  -6.36490395e-02  -4.64390347e-02  -6.80136630e-02
   -1.50110391e-02  -1.26706539e-01  -1.50893427e-02  -9.37370546e-02
   -8.15202139e-04  -9.19957063e-02  -5.23791534e-02  -3.94065473e-03
   -1.26180466e-01  -1.83992221e-04  -4.32039412e-02  -1.14470771e-01
   -5.96937328e-02  -8.10854273e-02  -1.13713168e-01  -1.27270304e-02
   -1.26492406e-01  -1.26046902e-01  -1.27808672e-02  -2.87899988e-02
   -1.21783363e-01  -5.16853224e-02  -2.31727321e-02  -2.60931347e-04
   -6.27375229e-02  -1.54776005e-02  -1.08465655e-01  -5.11047322e-02
   -1.16359721e-01  -2.49400628e-03  -1.35866355e-02  -2.88037760e-02
   -1.04822237e-01  -3.41518299e-02  -1.20051180e-01  -2.96169321e-02
   -1.12666172e-01  -1.78351080e-02  -5.76406184e-02  -6.55777834e-02
   -8.85722851e-04  -7.08345817e-02  -1.03206724e-01  -2.88693468e-03
   -3.65934493e-03  -7.53672528e-04  -1.49170510e-02  -9.44199325e-02
   -5.63590602e-03  -4.60832176e-02  -5.23419049e-03  -1.76060776e-02]
 [ -1.40317999e-01  -6.00994719e-02  -7.31751560e-02  -5.13436708e-02
   -1.30227282e-01  -8.44309106e-02  -1.77839350e-03  -1.11723990e-01
   -2.25412140e-03  -1.22203864e-01  -6.42144406e-03  -2.44965308e-02
   -8.80522102e-03  -1.34864050e-02  -7.32469588e-02  -1.20034026e-01
   -1.07579741e-01  -4.84402575e-03  -1.05199783e-01  -1.26772940e-01
   -9.92106572e-02  -8.21734994e-04  -1.23495012e-01  -2.42707979e-02
   -1.21548940e-01  -1.37963572e-01  -1.14205290e-01  -3.65873294e-02
   -5.72209524e-02  -1.22965031e-01  -1.16480037e-01  -1.31119451e-01
   -7.94000748e-03  -3.19914831e-02  -4.63819184e-02  -1.15001404e-02
   -1.40966732e-01  -1.08125388e-03  -1.37905151e-01  -1.27349034e-01
   -4.19259217e-03  -1.31683561e-01  -5.90511651e-02  -1.07374476e-01
   -4.35968233e-02  -7.09881085e-02  -5.17936996e-02  -7.58559960e-02
   -1.67418909e-02  -1.41316469e-01  -1.68292232e-02  -1.04545430e-01
   -9.09199232e-04  -1.02603295e-01  -5.84187452e-02  -4.39503295e-03
   -1.40729738e-01  -2.05207491e-04  -4.81855828e-02  -1.27669853e-01
   -6.65767341e-02  -9.04350034e-02  -1.26824894e-01  -1.41945239e-02
   -1.41077646e-01  -1.40580773e-01  -1.42545683e-02  -3.21096371e-02
   -1.35825625e-01  -5.76449118e-02  -2.58446700e-02  -2.91018103e-04
   -6.99714892e-02  -1.72622492e-02  -1.20972315e-01  -5.69973765e-02
   -1.29776609e-01  -2.78157832e-03  -1.51532460e-02  -3.21250028e-02
   -1.16908792e-01  -3.80897155e-02  -1.33893712e-01  -3.30319202e-02
   -1.25657174e-01  -1.98915898e-02  -6.42868848e-02  -7.31392466e-02
   -9.87851353e-04  -7.90021814e-02  -1.15107002e-01  -3.21981343e-03
   -4.08128664e-03  -8.40574933e-04  -1.66370654e-02  -1.05307047e-01
   -6.28575562e-03  -5.13968549e-02  -5.83772018e-03  -1.96361510e-02]
 [ -1.27432725e-01  -5.45805921e-02  -6.64555480e-02  -4.66288283e-02
   -1.18268629e-01  -7.66776969e-02  -1.61508524e-03  -1.01464478e-01
   -2.04712749e-03  -1.10981995e-01  -5.83176870e-03  -2.22470367e-02
   -7.99664559e-03  -1.22479607e-02  -6.65207573e-02  -1.09011411e-01
   -9.77007915e-02  -4.39920328e-03  -9.55393830e-02  -1.15131497e-01
   -9.01002328e-02  -7.46275817e-04  -1.12154577e-01  -2.20420326e-02
   -1.10387211e-01  -1.25294503e-01  -1.03717922e-01  -3.32275483e-02
   -5.19664044e-02  -1.11673264e-01  -1.05783781e-01  -1.19078872e-01
   -7.21088383e-03  -2.90537343e-02  -4.21227091e-02  -1.04440930e-02
   -1.28021885e-01  -9.81963322e-04  -1.25241446e-01  -1.15654688e-01
   -3.80759025e-03  -1.19591179e-01  -5.36285504e-02  -9.75143755e-02
   -3.95933667e-02  -6.44693351e-02  -4.70375313e-02  -6.88902089e-02
   -1.52044983e-02  -1.28339506e-01  -1.52838110e-02  -9.49451182e-02
   -8.25708294e-04  -9.31813278e-02  -5.30542050e-02  -3.99144107e-03
   -1.27806654e-01  -1.86363474e-04  -4.37607446e-02  -1.15946047e-01
   -6.04630532e-02  -8.21304394e-02  -1.15178679e-01  -1.28910537e-02
   -1.28122614e-01  -1.27671368e-01  -1.29455843e-02  -2.91610383e-02
   -1.23352882e-01  -5.23514320e-02  -2.34713774e-02  -2.64294176e-04
   -6.35460710e-02  -1.56770726e-02  -1.09863538e-01  -5.17633593e-02
   -1.17859341e-01  -2.52614852e-03  -1.37617372e-02  -2.91749930e-02
   -1.06173164e-01  -3.45919716e-02  -1.21598374e-01  -2.99986290e-02
   -1.14118190e-01  -1.80649632e-02  -5.83834787e-02  -6.64229362e-02
   -8.97137862e-04  -7.17474830e-02  -1.04536831e-01  -2.92414089e-03
   -3.70650581e-03  -7.63385702e-04  -1.51092988e-02  -9.56367969e-02
   -5.70854040e-03  -4.66771285e-02  -5.30164765e-03  -1.78329811e-02]
 [ -4.94433284e-03  -2.11770260e-03  -2.57844559e-03  -1.80917772e-03
   -4.58876999e-03  -2.97506040e-03  -6.26645863e-05  -3.93677643e-03
   -7.94276325e-05  -4.30605184e-03  -2.26270022e-04  -8.63175089e-04
   -3.10266278e-04  -4.75215408e-04  -2.58097568e-03  -4.22959407e-03
   -3.79074708e-03  -1.70687123e-04  -3.70688540e-03  -4.46705066e-03
   -3.49584880e-03  -2.89551685e-05  -4.35154751e-03  -8.55221024e-04
   -4.28297451e-03  -4.86137076e-03  -4.02420908e-03  -1.28921404e-03
   -2.01627329e-03  -4.33287279e-03  -4.10436348e-03  -4.62020704e-03
   -2.79779073e-04  -1.12727192e-03  -1.63434230e-03  -4.05226144e-04
   -4.96719199e-03  -3.80997384e-05  -4.85931219e-03  -4.48735026e-03
   -1.47732801e-04  -4.64008435e-03  -2.08076381e-03  -3.78351423e-03
   -1.53620495e-03  -2.50138142e-03  -1.82503521e-03  -2.67290934e-03
   -5.89927744e-04  -4.97951554e-03  -5.93005041e-04  -3.68382819e-03
   -3.20371131e-05  -3.61539391e-03  -2.05847946e-03  -1.54866131e-04
   -4.95884110e-03  -7.23081958e-06  -1.69789735e-03  -4.49865484e-03
   -2.34593947e-03  -3.18662437e-03  -4.46888133e-03  -5.00167128e-04
   -4.97110021e-03  -4.95359208e-03  -5.02282891e-04  -1.13143527e-03
   -4.78603673e-03  -2.03121219e-03  -9.10678964e-04  -1.02544960e-05
   -2.46555918e-03  -6.08263415e-04  -4.26265621e-03  -2.00839523e-03
   -4.57288980e-03  -9.80134345e-05  -5.33949258e-04  -1.13197670e-03
   -4.11947135e-03  -1.34215305e-03  -4.71796262e-03  -1.16393341e-03
   -4.42773483e-03  -7.00912506e-04  -2.26525290e-03  -2.57718027e-03
   -3.48085485e-05  -2.78377030e-03  -4.05598236e-03  -1.13455361e-04
   -1.43810770e-04  -2.96190244e-05  -5.86234047e-04  -3.71066502e-03
   -2.21488819e-04  -1.81105174e-03  -2.05701561e-04  -6.91911703e-04]
 [  1.42344313e-01   6.09673605e-02   7.42318688e-02   5.20851180e-02
    1.32107877e-01   8.56501662e-02   1.80407505e-03   1.13337381e-01
    2.28667287e-03   1.23968594e-01   6.51417529e-03   2.48502820e-02
    8.93237605e-03   1.36811604e-02   7.43047085e-02   1.21767422e-01
    1.09133286e-01   4.91397769e-03   1.06718960e-01   1.28603652e-01
    1.00643345e-01   8.33601560e-04   1.25278387e-01   2.46212893e-02
    1.23304212e-01   1.39955886e-01   1.15854514e-01   3.71156822e-02
    5.80472726e-02   1.24740753e-01   1.18162110e-01   1.33012930e-01
    8.05466809e-03   3.24534679e-02   4.70517136e-02   1.16662124e-02
    1.43002414e-01   1.09686813e-03   1.39896621e-01   1.29188065e-01
    4.25313684e-03   1.33585186e-01   5.99039152e-02   1.08925057e-01
    4.42263993e-02   7.20132384e-02   5.25416455e-02   7.69514224e-02
    1.69836583e-02   1.43357201e-01   1.70722518e-02   1.06055157e-01
    9.22328858e-04   1.04084976e-01   5.92623626e-02   4.45850104e-03
    1.42761997e-01   2.08170866e-04   4.88814244e-02   1.29513517e-01
    6.75381599e-02   9.17409634e-02   1.28656356e-01   1.43995052e-02
    1.43114929e-01   1.42610881e-01   1.44604167e-02   3.25733281e-02
    1.37787065e-01   5.84773544e-02   2.62178894e-02   2.95220657e-04
    7.09819382e-02   1.75115310e-02   1.22719261e-01   5.78204681e-02
    1.31650696e-01   2.82174673e-03   1.53720720e-02   3.25889157e-02
    1.18597056e-01   3.86397640e-02   1.35827253e-01   3.35089298e-02
    1.27471773e-01   2.01788416e-02   6.52152433e-02   7.41954409e-02
    1.00211678e-03   8.01430415e-02   1.16769247e-01   3.26631033e-03
    4.14022397e-03   8.52713565e-04   1.68773190e-02   1.06827772e-01
    6.37652738e-03   5.21390701e-02   5.92202192e-03   1.99197140e-02]
 [ -1.14328196e-01  -4.89678034e-02  -5.96215996e-02  -4.18337582e-02
   -1.06106488e-01  -6.87925550e-02  -1.44899814e-03  -9.10303902e-02
   -1.83661138e-03  -9.95691744e-02  -5.23205946e-03  -1.99592653e-02
   -7.17431149e-03  -1.09884431e-02  -5.96801031e-02  -9.78012355e-02
   -8.76537421e-02  -3.94681173e-03  -8.57146019e-02  -1.03291963e-01
   -8.08347861e-02  -6.69532632e-04  -1.00621175e-01  -1.97753428e-02
   -9.90355554e-02  -1.12409857e-01  -9.30521021e-02  -2.98105973e-02
   -4.66224454e-02  -1.00189357e-01  -9.49055187e-02  -1.06833410e-01
   -6.46935344e-03  -2.60659970e-02  -3.77910253e-02  -9.37007591e-03
   -1.14856770e-01  -8.80983240e-04  -1.12362257e-01  -1.03761352e-01
   -3.41603716e-03  -1.07293034e-01  -4.81136647e-02  -8.74864963e-02
   -3.55217876e-02  -5.78396387e-02  -4.22004323e-02  -6.18058924e-02
   -1.36409455e-02  -1.15141728e-01  -1.37121021e-02  -8.51814482e-02
   -7.40796679e-04  -8.35990370e-02  -4.75983821e-02  -3.58098170e-03
   -1.14663672e-01  -1.67198808e-04  -3.92606136e-02  -1.04022749e-01
   -5.42453423e-02  -7.36845654e-02  -1.03334294e-01  -1.15654037e-02
   -1.14947140e-01  -1.14542298e-01  -1.16143267e-02  -2.61622664e-02
   -1.10667903e-01  -4.69678787e-02  -2.10577011e-02  -2.37115516e-04
   -5.70113184e-02  -1.40649227e-02  -9.85657340e-02  -4.64402804e-02
   -1.05739290e-01  -2.26637233e-03  -1.23465506e-02  -2.61747861e-02
   -9.52548592e-02  -3.10347103e-02  -1.09093820e-01  -2.69137235e-02
   -1.02382860e-01  -1.62072549e-02  -5.23796206e-02  -5.95923414e-02
   -8.04880797e-04  -6.43693391e-02  -9.37867983e-02  -2.62343721e-03
   -3.32534772e-03  -6.84883024e-04  -1.35555359e-02  -8.58019982e-02
   -5.12150332e-03  -4.18770915e-02  -4.75645334e-03  -1.59991286e-02]
 [ -4.00421329e-02  -1.71504087e-02  -2.08817781e-02  -1.46517916e-02
   -3.71625746e-02  -2.40937995e-02  -5.07494899e-04  -3.18823449e-02
   -6.43251965e-04  -3.48729557e-02  -1.83246852e-03  -6.99050262e-03
   -2.51271991e-03  -3.84857556e-03  -2.09022682e-02  -3.42537555e-02
   -3.06997129e-02  -1.38232532e-03  -3.00205514e-02  -3.61768194e-02
   -2.83114521e-02  -2.34496087e-04  -3.52414066e-02  -6.92608589e-03
   -3.46860618e-02  -3.93702569e-02  -3.25904263e-02  -1.04408181e-02
   -1.63289741e-02  -3.50901676e-02  -3.32395640e-02  -3.74171705e-02
   -2.26581648e-03  -9.12931502e-03  -1.32358710e-02  -3.28176109e-03
   -4.02272598e-02  -3.08554226e-04  -3.93535854e-02  -3.63412176e-02
   -1.19642764e-03  -3.75781486e-02  -1.68512565e-02  -3.06411369e-02
   -1.24410967e-02  -2.02576668e-02  -1.47802150e-02  -2.16468014e-02
   -4.77758393e-03  -4.03270632e-02  -4.80250571e-03  -2.98338204e-02
   -2.59455498e-04  -2.92795991e-02  -1.66707847e-02  -1.25419757e-03
   -4.01596294e-02  -5.85594555e-05  -1.37505774e-02  -3.64327688e-02
   -1.89988059e-02  -2.58071697e-02  -3.61916453e-02  -4.05064935e-03
   -4.02589110e-02  -4.01171198e-02  -4.06778405e-03  -9.16303226e-03
   -3.87601574e-02  -1.64499582e-02  -7.37521711e-03  -8.30469763e-05
   -1.99675571e-02  -4.92607705e-03  -3.45215122e-02  -1.62651729e-02
   -3.70339674e-02  -7.93770788e-04  -4.32423703e-03  -9.16741714e-03
   -3.33619165e-02  -1.08695496e-02  -3.82088530e-02  -9.42622146e-03
   -3.58584166e-02  -5.67640421e-03  -1.83453584e-02  -2.08715307e-02
   -2.81900222e-04  -2.25446191e-02  -3.28477451e-02  -9.18828645e-04
   -1.16466471e-03  -2.39872385e-04  -4.74767019e-03  -3.00511609e-02
   -1.79374751e-03  -1.46669686e-02  -1.66589296e-03  -5.60351038e-03]
 [ -1.13147639e-01  -4.84621599e-02  -5.90059446e-02  -4.14017812e-02
   -1.05010829e-01  -6.80822004e-02  -1.43403573e-03  -9.00904068e-02
   -1.81764645e-03  -9.85410191e-02  -5.17803300e-03  -1.97531651e-02
   -7.10022926e-03  -1.08749760e-02  -5.90638439e-02  -9.67913361e-02
   -8.67486261e-02  -3.90605679e-03  -8.48295095e-02  -1.02225366e-01
   -8.00000829e-02  -6.62619011e-04  -9.95821563e-02  -1.95711418e-02
   -9.80129104e-02  -1.11249109e-01  -9.20912424e-02  -2.95027719e-02
   -4.61410202e-02  -9.91547981e-02  -9.39255205e-02  -1.05730244e-01
   -6.40255064e-03  -2.57968385e-02  -3.74007936e-02  -9.27332013e-03
   -1.13670754e-01  -8.71886172e-04  -1.11202000e-01  -1.02689908e-01
   -3.38076302e-03  -1.06185122e-01  -4.76168411e-02  -8.65831072e-02
   -3.51549882e-02  -5.72423843e-02  -4.17646690e-02  -6.11676823e-02
   -1.35000885e-02  -1.13952770e-01  -1.35705104e-02  -8.43018612e-02
   -7.33147183e-04  -8.27357900e-02  -4.71068793e-02  -3.54400434e-03
   -1.13479650e-01  -1.65472307e-04  -3.88552069e-02  -1.02948606e-01
   -5.36852027e-02  -7.29236956e-02  -1.02267260e-01  -1.14459789e-02
   -1.13760191e-01  -1.13359530e-01  -1.14943967e-02  -2.58921138e-02
   -1.09525142e-01  -4.64828865e-02  -2.08402585e-02  -2.34667051e-04
   -5.64226172e-02  -1.39196877e-02  -9.75479403e-02  -4.59607362e-02
   -1.04647421e-01  -2.24296968e-03  -1.22190596e-02  -2.59045042e-02
   -9.42712537e-02  -3.07142446e-02  -1.07967313e-01  -2.66358114e-02
   -1.01325650e-01  -1.60398981e-02  -5.18387466e-02  -5.89769885e-02
   -7.96569565e-04  -6.37046587e-02  -9.28183521e-02  -2.59634749e-03
   -3.29101005e-03  -6.77810895e-04  -1.34155608e-02  -8.49160034e-02
   -5.06861848e-03  -4.14446670e-02  -4.70733801e-03  -1.58339210e-02]
 [ -2.04282876e-02  -8.74962088e-03  -1.06532529e-02  -7.47490186e-03
   -1.89592239e-02  -1.22919293e-02  -2.58908579e-04  -1.62654101e-02
   -3.28167737e-04  -1.77911294e-02  -9.34870129e-04  -3.56634344e-03
   -1.28191385e-03  -1.96342709e-03  -1.06637063e-02  -1.74752322e-02
   -1.56620669e-02  -7.05220653e-04  -1.53155792e-02  -1.84563213e-02
   -1.44436483e-02  -1.19632826e-04  -1.79791019e-02  -3.53347997e-03
   -1.76957818e-02  -2.00855167e-02  -1.66266518e-02  -5.32659026e-03
   -8.33054973e-03  -1.79019444e-02  -1.69578223e-02  -1.90891110e-02
   -1.15595118e-03  -4.65750097e-03  -6.75254189e-03  -1.67425545e-03
   -2.05227338e-02  -1.57415053e-04  -2.00770114e-02  -1.85401923e-02
   -6.10381270e-04  -1.91712372e-02  -8.59700245e-03  -1.56321832e-02
   -6.34707200e-03  -1.03348501e-02  -7.54041958e-03  -1.10435447e-02
   -2.43737912e-03  -2.05736504e-02  -2.45009346e-03  -1.52203147e-02
   -1.32366364e-04  -1.49375677e-02  -8.50493118e-03  -6.39853742e-04
   -2.04882308e-02  -2.98752667e-05  -7.01512955e-03  -1.85868990e-02
   -9.69261732e-03  -1.31660390e-02  -1.84638850e-02  -2.06651904e-03
   -2.05388812e-02  -2.04665436e-02  -2.07526064e-03  -4.67470249e-03
   -1.97742624e-02  -8.39227214e-03  -3.76261316e-03  -4.23680607e-05
   -1.01868450e-02  -2.51313582e-03  -1.76118336e-02  -8.29800029e-03
   -1.88936124e-02  -4.04957897e-04  -2.20609521e-03  -4.67693952e-03
   -1.70202428e-02  -5.54531611e-03  -1.94930035e-02  -4.80897367e-03
   -1.82938818e-02  -2.89593009e-03  -9.35924812e-03  -1.06480250e-02
   -1.43816985e-04  -1.15015842e-02  -1.67579281e-02  -4.68758642e-04
   -5.94176782e-04  -1.22375651e-04  -2.42211803e-03  -1.53311953e-02
   -9.15115838e-04  -7.48264469e-03  -8.49888305e-04  -2.85874186e-03]]

Body:
You need to help python break the line correctly:

self.who += self.lr * numpy.dot
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs))

python "breaks the line" after numpy.dot because it has no cue that the line goes further.

On the other hand, when you print:

print (numpy.dot
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs)))

The entire expressin is in parentheses, so python knows to read it fully.

Solution:

You can either place your expression in parentheses:

 self.who += (self.lr * numpy.dot
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs)))

Or, add an indication for python to continue reading the line

self.who += self.lr * numpy.dot \
    ((output_errors * final_outputs * (1.0 - final_outputs)),numpy.transpose(hidden_outputs))

For more information see this thread.


问:
warning: implicit declaration of function 'system'
I am getting an error in my compiler:

```<code>Warning: implicit declaration of function 'system'
</code>```

I added:

```<code>system("cls");
</code>```

To be able to clear the screen, and now I get the error. I am using this code to test:

```<code>#include <stdio.h>

int nothing; //random name

int main()
{
printf("this is a msg");
scanf("%d",&nothing);
system("cls");
printf("hello");
getchar();

return 0;
}
</code>```

This is just a test code, so it's very sloppy. I am new to coding so any help would be appreciated.

答:
For C++: #include <cstdlib>, for C: #include <stdlib.h>.

Or, you can do as follows:

```<code>#ifdef __cplusplus__
  #include <cstdlib>
#else
  #include <stdlib.h>
#endif

if (system("CLS")) system("clear");
</code>```

You can also see a full article w.r.t Clear the screen.

Body:
I am getting an error in my compiler:

Warning: implicit declaration of function 'system'

I added:

system("cls");

To be able to clear the screen, and now I get the error. I am using this code to test:

#include <stdio.h>

int nothing; //random name

int main()
{
printf("this is a msg");
scanf("%d",&nothing);
system("cls");
printf("hello");
getchar();

return 0;
}

This is just a test code, so it's very sloppy. I am new to coding so any help would be appreciated.

Body:
For C++: #include <cstdlib>, for C: #include <stdlib.h>.

Or, you can do as follows:

#ifdef __cplusplus__
  #include <cstdlib>
#else
  #include <stdlib.h>
#endif

if (system("CLS")) system("clear");

You can also see a full article w.r.t Clear the screen.