Tag Archives: solution

The method of constructing even order magic square (n = 4 * m)

For the number n divisible by 4, we can construct magic square as follows:

1. From left to right, from the first line to the nth line, in the order of 1, 2 And n ^ 2 fills this matrix.

2. Divide the above matrix into m ^ 2 small 4×4 matrices. For the number a on the two diagonals of each 4×4 small matrix, replace a with the complement of a, the square of N + 1-A.

That is: A & lt; – n ^ 2 + A-1

Word column after the text evenly distributed in the left and right two columns, rather than fill in the left column and then fill in the right column, how to do?

It should be that some paragraphs are selected when setting columns.
Solution:
reset the column, through the menu: format → column → column number set to 2, and set “apply to” to “whole document” → confirm.
After returning to the normal interface, delete all the “section break (continuous)” marks in the document. If you can’t see the “section break (continuous)” marks because they are hidden, you can click the “show/hide edit marks” button in the toolbar to show them.

Location of “show/hide edit mark” button:

Reference 1
reference 2

Error in plot.new() : figure margins too large

There is an error in drawing graphics using the plot function of rstudio

Error in plot.new () : figure margins too large

Solution:
use the code first

par("mar")

Check the Mar parameter and you’ll probably get this result

[1] 5.1 4.1 4.1 2.1

Reset this parameter

par(mar=c(1,1,1,1))

Then the problem was solved

source

cifar10.load_ The solution of data () Download error

Generally, the network connection is unstable. If you can’t download it on the server, you can use the link locally first http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz Download the data set, and then upload the file to the server

~/.keras/datasets

Finally, the document was renamed as:

 cifar-10-batches-py.tar.gz

Rerun the code, will automatically read data from the local file, no need to download online

reference resources

The GPU is still occupied after the program stops

When running deep learning programs, sometimes the program is forced to terminate, but the GPU resources occupied by the program are still not released. After being trapped for a long time, it is thought that the GPU has been occupied by others. As a result, the GPU resources are leaked.

You can use this command to view the usage of GPU in Linux system

nvidia-smi

The result is as shown in the figure

At this time, you can manually kill the process that occupies the GPU to release the GPU resources

kill -9 49461

If the screen command is used, the program running in the background stops and occupies the GPU, you can also close all screen windows to release the GPU

killall screen

Of course, it’s OK to kill the process directly

Android DP, SP to PX

private int dp2px(int value){
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,value,getResources()
                .getDisplayMetrics());
    }

    private int sp2px(int value){
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP,value,getResources()
                .getDisplayMetrics());
    }

original text

Getactionbar is null

We use getactionbar to get the actionbar instance, hide it or do other operations.

ActionBar actionBar = getActionBar();

But I did, but actionbar is null.

The problem is caused by the base class of activity. When using the base class of appcompatactivity or other support packages, you need to use another corresponding method to get the actionbar instance, that is, getsupportactionbar (), and the actionbar also needs to use the base class of the corresponding support package.

android.support.v7.app.ActionBar actionBar = getSupportActionBar();

In this way, the null pointer will not be reported.

original text

[Android] – Android studio + carefree simulator

It is too laggy for Andriod Studio to bring its own simulator, and VirtualBox is installed in Genymotion simulator, and then a bunch of settings will result in card B.

Online under a carefree simulator, this simulator is dedicated to the game, the current official version are Android 4. X version. I used Android 5.1, a beta version, to debug.

Setting method of Android studio + carefree simulator:

(how to install as and how to download and install Xiaoyao will not be mentioned.)

1. Set deployment target options

2. Running carefree simulator

3. Run the command line and switch the directory to the installed carefree Directory: (mine is on D: disk)

cd D:\Program Files\Microvirt\MEmu

4. Use the command to check the number of ports opened by the free running program

netstat -nb

The default port is 5037

Because there are too many ports on this computer, I use the command to write the output to a file

netstat -nb > c:\port.txt

Open C:\ port.txt You can find data like this:

5. Using command to connect Xiaoyao

adb.exe connect 127.0.0.1:5037

The connected prompt indicates that the connection is successful

6. Android studio point to run, select just successfully connected to the carefree simulator

PS: if Android studio can’t connect to night God, restart the simulator.
Original text

Notes on Java IO streaming

1: The solution to the garbled code in reading Chinese:
add the encoding mode “UTF-8” when constructing the inputstreamreader

BufferedReader br = new BufferedReader(new InputStreamReader(
                new FileInputStream(new File("F:/download/test.txt")),"utf-8"))

2: When using filewriter to write a file, you must add

fw.flush();

To write successfully.