java分數表示_表示Java分數的最佳方法?

小編典典

碰巧的是不久前我寫了一個BigFraction類,用于解決Euler項目問題。它保留了BigInteger分子和分母,因此它將永遠不會溢出。但是,對于許多你永遠不會溢出的操作來說,這會有點慢。無論如何,請根據需要使用它。我一直很想以某種方式炫耀它。:)

編輯:該代碼的最新,最出色的版本,包括單元測試,現在托管在GitHub上,也可以通過Maven Central獲得。我將原始代碼留在這里,以便此答案不僅僅是一個鏈接…

import java.math.*;

/**

* Arbitrary-precision fractions, utilizing BigIntegers for numerator and

* denominator. Fraction is always kept in lowest terms. Fraction is

* immutable, and guaranteed not to have a null numerator or denominator.

* Denominator will always be positive (so sign is carried by numerator,

* and a zero-denominator is impossible).

*/

public final class BigFraction extends Number implements Comparable

{

private static final long serialVersionUID = 1L; //because Number is Serializable

private final BigInteger numerator;

private final BigInteger denominator;

public final static BigFraction ZERO = new BigFraction(BigInteger.ZERO, BigInteger.ONE, true);

public final static BigFraction ONE = new BigFraction(BigInteger.ONE, BigInteger.ONE, true);

/**

* Constructs a BigFraction with given numerator and denominator. Fraction

* will be reduced to lowest terms. If fraction is negative, negative sign will

* be carried on numerator, regardless of how the values were passed in.

*/

public BigFraction(BigInteger numerator, BigInteger denominator)

{

if(numerator == null)

throw new IllegalArgumentException("Numerator is null");

if(denominator == null)

throw new IllegalArgumentException("Denominator is null");

if(denominator.equals(BigInteger.ZERO))

throw new ArithmeticException("Divide by zero.");

//only numerator should be negative.

if(denominator.signum() < 0)

{

numerator = numerator.negate();

denominator = denominator.negate();

}

//create a reduced fraction

BigInteger gcd = numerator.gcd(denominator);

this.numerator = numerator.divide(gcd);

this.denominator = denominator.divide(gcd);

}

/**

* Constructs a BigFraction from a whole number.

*/

public BigFraction(BigInteger numerator)

{

this(numerator, BigInteger.ONE, true);

}

public BigFraction(long numerator, long denominator)

{

this(BigInteger.valueOf(numerator), BigInteger.valueOf(denominator));

}

public BigFraction(long numerator)

{

this(BigInteger.valueOf(numerator), BigInteger.ONE, true);

}

/**

* Constructs a BigFraction from a floating-point number.

*

* Warning: round-off error in IEEE floating point numbers can result

* in answers that are unexpected. For example,

* System.out.println(new BigFraction(1.1))

* will print:

* 2476979795053773/2251799813685248

*

* This is because 1.1 cannot be expressed exactly in binary form. The

* given fraction is exactly equal to the internal representation of

* the double-precision floating-point number. (Which, for 1.1, is:

* (-1)^0 * 2^0 * (1 + 0x199999999999aL / 0x10000000000000L).)

*

* NOTE: In many cases, BigFraction(Double.toString(d)) may give a result

* closer to what the user expects.

*/

public BigFraction(double d)

{

if(Double.isInfinite(d))

throw new IllegalArgumentException("double val is infinite");

if(Double.isNaN(d))

throw new IllegalArgumentException("double val is NaN");

//special case - math below won't work right for 0.0 or -0.0

if(d == 0)

{

numerator = BigInteger.ZERO;

denominator = BigInteger.ONE;

return;

}

final long bits = Double.doubleToLongBits(d);

final int sign = (int)(bits >> 63) & 0x1;

final int exponent = ((int)(bits >> 52) & 0x7ff) - 0x3ff;

final long mantissa = bits & 0xfffffffffffffL;

//number is (-1)^sign * 2^(exponent) * 1.mantissa

BigInteger tmpNumerator = BigInteger.valueOf(sign==0 ? 1 : -1);

BigInteger tmpDenominator = BigInteger.ONE;

//use shortcut: 2^x == 1 << x. if x is negative, shift the denominator

if(exponent >= 0)

tmpNumerator = tmpNumerator.multiply(BigInteger.ONE.shiftLeft(exponent));

else

tmpDenominator = tmpDenominator.multiply(BigInteger.ONE.shiftLeft(-exponent));

//1.mantissa == 1 + mantissa/2^52 == (2^52 + mantissa)/2^52

tmpDenominator = tmpDenominator.multiply(BigInteger.valueOf(0x10000000000000L));

tmpNumerator = tmpNumerator.multiply(BigInteger.valueOf(0x10000000000000L + mantissa));

BigInteger gcd = tmpNumerator.gcd(tmpDenominator);

numerator = tmpNumerator.divide(gcd);

denominator = tmpDenominator.divide(gcd);

}

/**

* Constructs a BigFraction from two floating-point numbers.

*

* Warning: round-off error in IEEE floating point numbers can result

* in answers that are unexpected. See BigFraction(double) for more

* information.

*

* NOTE: In many cases, BigFraction(Double.toString(numerator) + "/" + Double.toString(denominator))

* may give a result closer to what the user expects.

*/

public BigFraction(double numerator, double denominator)

{

if(denominator == 0)

throw new ArithmeticException("Divide by zero.");

BigFraction tmp = new BigFraction(numerator).divide(new BigFraction(denominator));

this.numerator = tmp.numerator;

this.denominator = tmp.denominator;

}

/**

* Constructs a new BigFraction from the given BigDecimal object.

*/

public BigFraction(BigDecimal d)

{

this(d.scale() < 0 ? d.unscaledValue().multiply(BigInteger.TEN.pow(-d.scale())) : d.unscaledValue(),

d.scale() < 0 ? BigInteger.ONE : BigInteger.TEN.pow(d.scale()));

}

public BigFraction(BigDecimal numerator, BigDecimal denominator)

{

if(denominator.equals(BigDecimal.ZERO))

throw new ArithmeticException("Divide by zero.");

BigFraction tmp = new BigFraction(numerator).divide(new BigFraction(denominator));

this.numerator = tmp.numerator;

this.denominator = tmp.denominator;

}

/**

* Constructs a BigFraction from a String. Expected format is numerator/denominator,

* but /denominator part is optional. Either numerator or denominator may be a floating-

* point decimal number, which in the same format as a parameter to the

* BigDecimal(String) constructor.

*

* @throws NumberFormatException if the string cannot be properly parsed.

*/

public BigFraction(String s)

{

int slashPos = s.indexOf('/');

if(slashPos < 0)

{

BigFraction res = new BigFraction(new BigDecimal(s));

this.numerator = res.numerator;

this.denominator = res.denominator;

}

else

{

BigDecimal num = new BigDecimal(s.substring(0, slashPos));

BigDecimal den = new BigDecimal(s.substring(slashPos+1, s.length()));

BigFraction res = new BigFraction(num, den);

this.numerator = res.numerator;

this.denominator = res.denominator;

}

}

/**

* Returns this + f.

*/

public BigFraction add(BigFraction f)

{

if(f == null)

throw new IllegalArgumentException("Null argument");

//n1/d1 + n2/d2 = (n1*d2 + d1*n2)/(d1*d2)

return new BigFraction(numerator.multiply(f.denominator).add(denominator.multiply(f.numerator)),

denominator.multiply(f.denominator));

}

/**

* Returns this + b.

*/

public BigFraction add(BigInteger b)

{

if(b == null)

throw new IllegalArgumentException("Null argument");

//n1/d1 + n2 = (n1 + d1*n2)/d1

return new BigFraction(numerator.add(denominator.multiply(b)),

denominator, true);

}

/**

* Returns this + n.

*/

public BigFraction add(long n)

{

return add(BigInteger.valueOf(n));

}

/**

* Returns this - f.

*/

public BigFraction subtract(BigFraction f)

{

if(f == null)

throw new IllegalArgumentException("Null argument");

return new BigFraction(numerator.multiply(f.denominator).subtract(denominator.multiply(f.numerator)),

denominator.multiply(f.denominator));

}

/**

* Returns this - b.

*/

public BigFraction subtract(BigInteger b)

{

if(b == null)

throw new IllegalArgumentException("Null argument");

return new BigFraction(numerator.subtract(denominator.multiply(b)),

denominator, true);

}

/**

* Returns this - n.

*/

public BigFraction subtract(long n)

{

return subtract(BigInteger.valueOf(n));

}

/**

* Returns this * f.

*/

public BigFraction multiply(BigFraction f)

{

if(f == null)

throw new IllegalArgumentException("Null argument");

return new BigFraction(numerator.multiply(f.numerator), denominator.multiply(f.denominator));

}

/**

* Returns this * b.

*/

public BigFraction multiply(BigInteger b)

{

if(b == null)

throw new IllegalArgumentException("Null argument");

return new BigFraction(numerator.multiply(b), denominator);

}

/**

* Returns this * n.

*/

public BigFraction multiply(long n)

{

return multiply(BigInteger.valueOf(n));

}

/**

* Returns this / f.

*/

public BigFraction divide(BigFraction f)

{

if(f == null)

throw new IllegalArgumentException("Null argument");

if(f.numerator.equals(BigInteger.ZERO))

throw new ArithmeticException("Divide by zero");

return new BigFraction(numerator.multiply(f.denominator), denominator.multiply(f.numerator));

}

/**

* Returns this / b.

*/

public BigFraction divide(BigInteger b)

{

if(b == null)

throw new IllegalArgumentException("Null argument");

if(b.equals(BigInteger.ZERO))

throw new ArithmeticException("Divide by zero");

return new BigFraction(numerator, denominator.multiply(b));

}

/**

* Returns this / n.

*/

public BigFraction divide(long n)

{

return divide(BigInteger.valueOf(n));

}

/**

* Returns this^exponent.

*/

public BigFraction pow(int exponent)

{

if(exponent == 0)

return BigFraction.ONE;

else if (exponent == 1)

return this;

else if (exponent < 0)

return new BigFraction(denominator.pow(-exponent), numerator.pow(-exponent), true);

else

return new BigFraction(numerator.pow(exponent), denominator.pow(exponent), true);

}

/**

* Returns 1/this.

*/

public BigFraction reciprocal()

{

if(this.numerator.equals(BigInteger.ZERO))

throw new ArithmeticException("Divide by zero");

return new BigFraction(denominator, numerator, true);

}

/**

* Returns the complement of this fraction, which is equal to 1 - this.

* Useful for probabilities/statistics.

*/

public BigFraction complement()

{

return new BigFraction(denominator.subtract(numerator), denominator, true);

}

/**

* Returns -this.

*/

public BigFraction negate()

{

return new BigFraction(numerator.negate(), denominator, true);

}

/**

* Returns -1, 0, or 1, representing the sign of this fraction.

*/

public int signum()

{

return numerator.signum();

}

/**

* Returns the absolute value of this.

*/

public BigFraction abs()

{

return (signum() < 0 ? negate() : this);

}

/**

* Returns a string representation of this, in the form

* numerator/denominator.

*/

public String toString()

{

return numerator.toString() + "/" + denominator.toString();

}

/**

* Returns if this object is equal to another object.

*/

public boolean equals(Object o)

{

if(!(o instanceof BigFraction))

return false;

BigFraction f = (BigFraction)o;

return numerator.equals(f.numerator) && denominator.equals(f.denominator);

}

/**

* Returns a hash code for this object.

*/

public int hashCode()

{

//using the method generated by Eclipse, but streamlined a bit..

return (31 + numerator.hashCode())*31 + denominator.hashCode();

}

/**

* Returns a negative, zero, or positive number, indicating if this object

* is less than, equal to, or greater than f, respectively.

*/

public int compareTo(BigFraction f)

{

if(f == null)

throw new IllegalArgumentException("Null argument");

//easy case: this and f have different signs

if(signum() != f.signum())

return signum() - f.signum();

//next easy case: this and f have the same denominator

if(denominator.equals(f.denominator))

return numerator.compareTo(f.numerator);

//not an easy case, so first make the denominators equal then compare the numerators

return numerator.multiply(f.denominator).compareTo(denominator.multiply(f.numerator));

}

/**

* Returns the smaller of this and f.

*/

public BigFraction min(BigFraction f)

{

if(f == null)

throw new IllegalArgumentException("Null argument");

return (this.compareTo(f) <= 0 ? this : f);

}

/**

* Returns the maximum of this and f.

*/

public BigFraction max(BigFraction f)

{

if(f == null)

throw new IllegalArgumentException("Null argument");

return (this.compareTo(f) >= 0 ? this : f);

}

/**

* Returns a positive BigFraction, greater than or equal to zero, and less than one.

*/

public static BigFraction random()

{

return new BigFraction(Math.random());

}

public final BigInteger getNumerator() { return numerator; }

public final BigInteger getDenominator() { return denominator; }

//implementation of Number class. may cause overflow.

public byte byteValue() { return (byte) Math.max(Byte.MIN_VALUE, Math.min(Byte.MAX_VALUE, longValue())); }

public short shortValue() { return (short)Math.max(Short.MIN_VALUE, Math.min(Short.MAX_VALUE, longValue())); }

public int intValue() { return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, longValue())); }

public long longValue() { return Math.round(doubleValue()); }

public float floatValue() { return (float)doubleValue(); }

public double doubleValue() { return toBigDecimal(18).doubleValue(); }

/**

* Returns a BigDecimal representation of this fraction. If possible, the

* returned value will be exactly equal to the fraction. If not, the BigDecimal

* will have a scale large enough to hold the same number of significant figures

* as both numerator and denominator, or the equivalent of a double-precision

* number, whichever is more.

*/

public BigDecimal toBigDecimal()

{

//Implementation note: A fraction can be represented exactly in base-10 iff its

//denominator is of the form 2^a * 5^b, where a and b are nonnegative integers.

//(In other words, if there are no prime factors of the denominator except for

//2 and 5, or if the denominator is 1). So to determine if this denominator is

//of this form, continually divide by 2 to get the number of 2's, and then

//continually divide by 5 to get the number of 5's. Afterward, if the denominator

//is 1 then there are no other prime factors.

//Note: number of 2's is given by the number of trailing 0 bits in the number

int twos = denominator.getLowestSetBit();

BigInteger tmpDen = denominator.shiftRight(twos); // x / 2^n === x >> n

final BigInteger FIVE = BigInteger.valueOf(5);

int fives = 0;

BigInteger[] divMod = null;

//while(tmpDen % 5 == 0) { fives++; tmpDen /= 5; }

while(BigInteger.ZERO.equals((divMod = tmpDen.divideAndRemainder(FIVE))[1]))

{

fives++;

tmpDen = divMod[0];

}

if(BigInteger.ONE.equals(tmpDen))

{

//This fraction will terminate in base 10, so it can be represented exactly as

//a BigDecimal. We would now like to make the fraction of the form

//unscaled / 10^scale. We know that 2^x * 5^x = 10^x, and our denominator is

//in the form 2^twos * 5^fives. So use max(twos, fives) as the scale, and

//multiply the numerator and deminator by the appropriate number of 2's or 5's

//such that the denominator is of the form 2^scale * 5^scale. (Of course, we

//only have to actually multiply the numerator, since all we need for the

//BigDecimal constructor is the scale.

BigInteger unscaled = numerator;

int scale = Math.max(twos, fives);

if(twos < fives)

unscaled = unscaled.shiftLeft(fives - twos); //x * 2^n === x << n

else if (fives < twos)

unscaled = unscaled.multiply(FIVE.pow(twos - fives));

return new BigDecimal(unscaled, scale);

}

//else: this number will repeat infinitely in base-10. So try to figure out

//a good number of significant digits. Start with the number of digits required

//to represent the numerator and denominator in base-10, which is given by

//bitLength / log[2](10). (bitLenth is the number of digits in base-2).

final double LG10 = 3.321928094887362; //Precomputed ln(10)/ln(2), a.k.a. log[2](10)

int precision = Math.max(numerator.bitLength(), denominator.bitLength());

precision = (int)Math.ceil(precision / LG10);

//If the precision is less than 18 digits, use 18 digits so that the number

//will be at least as accurate as a cast to a double. For example, with

//the fraction 1/3, precision will be 1, giving a result of 0.3. This is

//quite a bit different from what a user would expect.

if(precision < 18)

precision = 18;

return toBigDecimal(precision);

}

/**

* Returns a BigDecimal representation of this fraction, with a given precision.

* @param precision the number of significant figures to be used in the result.

*/

public BigDecimal toBigDecimal(int precision)

{

return new BigDecimal(numerator).divide(new BigDecimal(denominator), new MathContext(precision, RoundingMode.HALF_EVEN));

}

//--------------------------------------------------------------------------

// PRIVATE FUNCTIONS

//--------------------------------------------------------------------------

/**

* Private constructor, used when you can be certain that the fraction is already in

* lowest terms. No check is done to reduce numerator/denominator. A check is still

* done to maintain a positive denominator.

*

* @param throwaway unused variable, only here to signal to the compiler that this

* constructor should be used.

*/

private BigFraction(BigInteger numerator, BigInteger denominator, boolean throwaway)

{

if(denominator.signum() < 0)

{

this.numerator = numerator.negate();

this.denominator = denominator.negate();

}

else

{

this.numerator = numerator;

this.denominator = denominator;

}

}

}

2020-03-19

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/541468.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/541468.shtml
英文地址,請注明出處:http://en.pswp.cn/news/541468.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《OpenStack云計算實戰手冊(第2版)》——1.7 添加用戶

本節書摘來自異步社區《OpenStack云計算實戰手冊&#xff08;第2版&#xff09;》一書中的第1章&#xff0c;第1.7節,作者&#xff1a; 【英】Kevin Jackson , 【美】Cody Bunch 更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 1.7 添加用戶 在OpenStack身份認證服務中…

開源軟件和自由軟件_自由和開源軟件的經濟學

開源軟件和自由軟件零邊際成本 (Zero Marginal Cost) At the core of the financial aspects of Free and Open Source is the zero negligible expense of merchandise in an environment that is digital. Right now, the rise of Free and Open Source speaks to an affirma…

java外部類_Java里什么叫內部類什么叫外部類

展開全部對普通類(沒有內部類的類)來說&#xff0c;62616964757a686964616fe78988e69d8331333337396234內部類和外部類都與他無關&#xff1b;對有內部類的類來說&#xff0c;它們就是其內部類的外部類&#xff0c;外部類是個相對的說法&#xff0c;其實就是有內部類的類。所以…

《精通Matlab數字圖像處理與識別》一6.2 傅立葉變換基礎知識

本節書摘來自異步社區《精通Matlab數字圖像處理與識別》一書中的第6章&#xff0c;第6.2節&#xff0c;作者 張錚 , 倪紅霞 , 苑春苗 , 楊立紅&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看 6.2 傅立葉變換基礎知識 精通Matlab數字圖像處理與識別要理解傅立…

多線程循環輸出abcc++_C ++循環| 查找輸出程序| 套裝5

多線程循環輸出abccProgram 1: 程序1&#xff1a; #include <iostream>using namespace std;int main(){int num 15673;int R1 0, R2 0;do {R1 num % 10;R2 R2 * 10 R1;num num / 10;} while (num > 0);cout << R2 << " ";return 0;}Ou…

java oql_深入理解java虛擬機(八):java內存分析工具-MAT和OQL

以下內容翻譯自MAT幫助文檔。一、Class HistogramClass Histogram shows the classes found in the snapshot, the number of objects for each class, the heap memory consumption of these objects, and the minimum retained size of the objects二、Dominator treeDomina…

《Python數據分析與挖掘實戰》一1.2 從餐飲服務到數據挖掘

本節書摘來自華章出版社《Python數據分析與挖掘實戰》一書中的第1章&#xff0c;第1.2節&#xff0c;作者 張良均 王路 譚立云 蘇劍林&#xff0c;更多章節內容可以訪問云棲社區“華章計算機”公眾號查看 1.2 從餐飲服務到數據挖掘 企業經營最大的目的就是盈利&#xff0c;而餐…

obj[]與obj._Ruby中帶有示例的Array.include?(obj)方法

obj[]與obj.Ruby Array.include&#xff1f;(obj)方法 (Ruby Array.include?(obj) Method) In the previous articles, we have seen how we can check whether two Array instances are identical or not with the help of <> operator, operator, and .eql? method?…

java javah_Java開發網 - 一個javah的問題

Posted by:jerry_xuPosted on:2006-03-13 15:39我在環境變量中已經設置了path為D:\Program Files\Java\jdk1.5.0_06&#xff0c;ClassPath設置為.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;class的路徑為&#xff1a;D:\JNItest\bin\jni\Hello.class &#xff0c;但是…

《Python面向對象編程指南》——2.7 __del__()方法

本節書摘來自異步社區《Python面向對象編程指南》一書中的第2章&#xff0c;第2.7節&#xff0c;作者&#xff3b;美&#xff3d;Steven F. Lott&#xff0c; 張心韜 蘭亮 譯&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 2.7 __del__()方法 __del__()方…

NullReferenceException C#中的異常

什么是NullReferenceException&#xff1f; (What is NullReferenceException?) NullReferenceException is an exception and it throws when the code is trying to access a reference that is not referencing to any object. If a reference variable/object is not refe…

java map key 大寫轉小寫_Spring JdbcTemplate 查詢出的Map,是如何產生大小寫忽略的Key的?(轉)...

Java 是區分大小寫的&#xff0c;普通的Map例如HashMap如果其中的key"ABC" value"XXX"那么map.get("Abc") 或 map.get("abc")是獲取不到值得。但Spring中產生了一個忽略大小寫的map使我產生了好奇例如 jdbcTemplate.queryForList(sql)…

《iOS 6核心開發手冊(第4版)》——2.11節秘訣:構建星星滑塊

本節書摘來自異步社區《iOS 6核心開發手冊&#xff08;第4版&#xff09;》一書中的第2章&#xff0c;第2.11節秘訣&#xff1a;構建星星滑塊&#xff0c;作者 【美】Erica Sadun&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看 2.11 秘訣&#xff1a;構建星星…

css框架和js框架_優雅設計的頂級CSS框架

css框架和js框架Brief discussion: 簡要討論&#xff1a; Well, who doesnt want their website or web page to look attractive, stylish and be responsive? 那么&#xff0c;誰不希望自己的網站或網頁看起來有吸引力&#xff0c;時尚并且ReactSwift&#xff1f; We put …

軟考下午題具體解釋---數據流圖設計

在歷年的軟考下午題其中&#xff0c;有五道大題。各自是數據流圖的設計&#xff0c;數據庫設計&#xff0c;uml圖&#xff0c;算法和設計模式&#xff0c;從今天這篇博文開始&#xff0c;小編就跟大家來一起學習軟考下午題的相關內容。包含理論上的知識以及典型例題的解說&…

基本程序 打印Scala的Hello World

Scala中的基本程序 (Basic program in Scala) As your first Scala program, we will see a basic output program that just prints "Hello World" or any other similar type of string. With this example, we will see what are the part of the code that is im…

java treemap lastkey_Java TreeMap lastKey()用法及代碼示例

java.util.TreeMap.lastKey()用于檢索Map中存在的最后一個或最高鍵。用法:tree_map.lastKey()參數&#xff1a;該方法不帶任何參數。返回值&#xff1a;該方法返回映射中存在的最后一個鍵。異常&#xff1a;如果映射為空&#xff0c;則該方法將引發NoSuchElementException。以下…

mysql屬于數據庫三級模式_數據庫系統的三級模式指的是什么

數據庫系統的三級模式指的是什么發布時間&#xff1a;2020-10-26 10:11:21來源&#xff1a;億速云閱讀&#xff1a;52作者&#xff1a;小新小編給大家分享一下數據庫系統的三級模式指的是什么&#xff0c;希望大家閱讀完這篇文章后大所收獲&#xff0c;下面讓我們一起去探討吧&…

《自頂向下網絡設計(第3版)》——導讀

目錄 第1部分 辨明客戶的需求和目標 第1章 分析商業目標和制約 1.1 采用自頂向下的網絡設計方法 1.2 分析商業目標 1.3 分析商業制約 1.4 商業目標檢查表 1.5 小結 1.6 復習題 1.7 設計環境 第2章 分析技術目標與折衷措施 2.1 可擴展性 2.2 可用性 2.3 網絡性能 2.4 安全性 2…

python矩陣變化_用numpy改變矩陣的形狀

我的問題有兩個方面。我有下面的代碼來處理一些矩陣。在import numpytupleList [(0, 122), (1, 246), (2, 157), (3, 166), (4, 315), (5, 108), (6, 172), (7, 20), (8, 173), (9, 38), (10, 28), (11, 72), (12, 102), (13, 277), (14, 318), (15, 316), (16, 283), (17, 31…